API för utvecklare
Vi <3 människor som kodar.
- 1. Mappstruktur
- 2. Verktyg
- 2.1. Inbyggd kommandorad
- 2.2. Inbyggd webbserver
- 2.3. Inbyggd webbredigerare
- 3. Objekt
- 3.1. Yellow
- 3.2. Yellow content
- 3.3. Yellow media
- 3.4. Yellow system
- 3.5. Yellow language
- 3.6. Yellow user
- 3.7. Yellow extension
- 3.8. Yellow lookup
- 3.9. Yellow toolbox
- 3.10. Yellow page
- 3.11. Yellow page collection
- 3.12. Yellow string
- 4. Händelser
- 4.1. Yellow core händelser
- 4.2. Yellow parse händelser
- 4.3. Yellow edit händelser
- 4.4. Yellow command händelser
- 5. Relaterad information
Mappstruktur
Du kan ändra allt i filhanteraren på din dator. Mappen content
innehåller webbplatsens innehållsfilerna. Du kan redigera din webbplats här. Mappen media
innehåller webbplatsens mediefiler. Du kan lagra dina bilder och filer här. Mappen system
innehåller webbplatsens systemfilerna. Du kan hitta installerade tillägg och konfigurationsfilar här.
Följande konfigurationsfiler och loggfiler är tillgängliga:
system/extensions/yellow-system.ini
= fil med systeminställningar
system/extensions/yellow-language.ini
= fil med språkinställningar
system/extensions/yellow-user.ini
= fil med användarinställningar
system/extensions/yellow-website.log
= loggfil för din webbplats
Verktyg
Inbyggd kommandorad
Du kan köra kommandon från kommandoraden. Detta ger dig möjlighet att bygga en statisk webbplats och göra andra saker. Öppna ett terminalfönster. Gå till installationsmappen där filen yellow.php
finns. Skriv php yellow.php
för att visa tillgängliga kommandona. De tillgängliga kommandona beror på installerade tillägg. Läs mer om kommandoraden.
Inbyggd webbserver
Du kan starta inbyggda webbservern på kommandoraden. Den inbyggda webbservern är praktisk för utvecklare, formgivare och översättare. Detta ger dig möjlighet att redigera webbsidor på din dator och ladda upp dem till din webbserver senare. Öppna ett terminalfönster. Gå till installationsmappen där filen yellow.php
finns. Skriv php yellow.php serve
, du kan valfritt ange en URL. Öppna en webbläsare och gå till URL:en som visas. Läs mer om webbservern.
Inbyggd webbredigerare
Du kan redigera din webbplats i en webbläsare. Inloggningssidan är tillgänglig på din webbplats som http://website/edit/
. Logga in med ditt användarkonto. Du kan använda vanliga navigeringen, göra ändringar och se resultatet omedelbart. Inbyggda webbredigeraren ger dig möjlighet att redigera innehållsfiler, ladda upp mediefiler och ändra inställningar. Det är ett utmärkt sätt att uppdatera webbsidor. Läs mer om webbredigeraren.
Objekt
Med hjälp av $this->yellow
kan du som utvecklare komma åt webbplatsen. API:et är uppdelat i flera objekt och speglar i princip filsystemet. Det finns $this->yellow->content
för att komma åt innehållsfiler, $this->yellow->media
för att komma åt mediafiler och $this->yellow->system
för att komma åt systeminställningar. Källkoden för API:et finns i filen system/extensions/core.php
.
Följande objekt är tillgängliga:
$this->yellow
= tillgång till API:et
$this->yellow->content
= tillgång till innehållsfiler
$this->yellow->media
= tillgång till mediefiler
$this->yellow->system
= tillgång till systeminställningar
$this->yellow->language
= tillgång till språkinställningar
$this->yellow->user
= tillgång till användarinställningar
$this->yellow->extension
= tillgång till tillägg
$this->yellow->lookup
= tillgång till uppslag och normalisering
$this->yellow->toolbox
= tillgång till verktygslådan med hjälpfunktioner
$this->yellow->page
= tillgång till aktuella sidan
Yellow
Klassen Yellow
ger tillgång till API:et. Följande metoder är tillgängliga:
command
getLayoutArguments
layout
load
log
request
Beskrivning av metoder och argument:
yellow->load(): void
Hantera initialisering
yellow->request(): int
Hantera begäran från webbläsaren
yellow->command($line = ""): int
Hantera kommandon från kommandoraden
yellow->log($action, $message): void
Skriv information till loggfilen
yellow->layout($name, $arguments = null): void
Inkludera layouten
yellow->getLayoutArguments($sizeMin = 9): array
Returnera layoutargument
Layoutfil med header och footer:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php echo $this->yellow->page->getContent() ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil som skickar ett argument:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $this->yellow->layout("hello", "World") ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil som tar emot ett argument:
<?php list($name, $text) = $this->yellow->getLayoutArguments() ?>
<p>
<?php echo "Hello $text" ?>
</p>
Yellow content
Klassen YellowContent
ger tillgång till innehållsfiler. Följande metoder är tillgängliga:
clean
find
index
multi
path
top
Beskrivning av metoder och argument:
content->find($location, $absoluteLocation = false): YellowPage|null
Returnera page, null om det inte finns
content->index($showInvisible = false, $multiLanguage = false, $levelMax = 0): YellowPageCollection
Returnera page collection med alla sidor
content->top($showInvisible = false, $showOnePager = true): YellowPageCollection
Returnera page collection med navigering på toppnivå
content->path($location, $absoluteLocation = false): YellowPageCollection
Returnera page collection med sökväg i navigering
content->multi($location, $absoluteLocation = false, $showInvisible = false): YellowPageCollection
Returnera page collection med flera språk i flerspråkigt läge
content->clean(): YellowPageCollection
Returnera page collection som är tom
Layoutfil för att visa alla sidor:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $pages = $this->yellow->content->index(true, true) ?>
<?php $this->yellow->page->setLastModified($pages->getModified()) ?>
<ul>
<?php foreach ($pages as $page): ?>
<li><?php echo $page->getHtml("title") ?></li>
<?php endforeach ?>
</ul>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa sidor under en viss plats:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $pages = $this->yellow->content->find("/help/")->getChildren() ?>
<?php $this->yellow->page->setLastModified($pages->getModified()) ?>
<ul>
<?php foreach ($pages as $page): ?>
<li><?php echo $page->getHtml("title") ?></li>
<?php endforeach ?>
</ul>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa navigationssidor på toppnivå:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $pages = $this->yellow->content->top() ?>
<?php $this->yellow->page->setLastModified($pages->getModified()) ?>
<ul>
<?php foreach ($pages as $page): ?>
<li><?php echo $page->getHtml("titleNavigation") ?></li>
<?php endforeach ?>
</ul>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Yellow media
Klassen YellowMedia
ger tillgång till mediefiler. Följande metoder är tillgängliga:
clean
index
find
Beskrivning av metoder och argument:
media->find($location, $absoluteLocation = false): YellowPage|null
Returnera page med information om mediefilen, null om det inte finns
media->index($showInvisible = false, $multiPass = false, $levelMax = 0): YellowPageCollection
Returnera page collection med alla mediefiler
media->clean(): YellowPageCollection
Returnera page collection som är tom
Layoutfil för att visa alla mediefiler:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $files = $this->yellow->media->index(true) ?>
<?php $this->yellow->page->setLastModified($files->getModified()) ?>
<ul>
<?php foreach ($files as $file): ?>
<li><?php echo $file->getLocation(true) ?></li>
<?php endforeach ?>
</ul>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa senaste mediefiler:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $files = $this->yellow->media->index()->sort("modified", false) ?>
<?php $this->yellow->page->setLastModified($files->getModified()) ?>
<ul>
<?php foreach ($files as $file): ?>
<li><?php echo $file->getLocation(true) ?></li>
<?php endforeach ?>
</ul>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa mediefiler av en viss typ:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $files = $this->yellow->media->index()->filter("type", "pdf") ?>
<?php $this->yellow->page->setLastModified($files->getModified()) ?>
<ul>
<?php foreach ($files as $file): ?>
<li><?php echo $file->getLocation(true) ?></li>
<?php endforeach ?>
</ul>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Yellow system
Klassen YellowSystem
ger tillgång till systeminställningar. Följande metoder är tillgängliga:
get
getAvailable
getDifferent
getHtml
getModified
getSettings
isExisting
save
set
setDefault
Beskrivning av metoder och argument:
system->save($fileName, $settings): bool
Spara systeminställningarna i filen
system->setDefault($key, $value): void
Ställ in standard systeminställning
system->set($key, $value): void
Ställ in systeminställning
system->get($key): string
Returnera systeminställning
system->getHtml($key): string
Returnera systeminställning, HTML-kodad
system->getDifferent($key): string
Returnera ett annat värde för en systeminställning
system->getAvailable($key): array
Returnera tillgängliga värden för en systeminställning
system->getSettings($filterStart = "", $filterEnd = ""): array
Returnera systeminställningar
system->getModified($httpFormat = false): int|string
Returnera ändringsdatum for systeminställningar, Unix-tid eller HTTP-format
system->isExisting($key): bool
Kontrollera om systeminställning finns
Layoutfil för att visa webbansvarig:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p>
<?php echo "Name: ".$this->yellow->system->getHtml("author")."<br />" ?>
<?php echo "Email: ".$this->yellow->system->getHtml("email")."<br />" ?>
</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att kontrollera om en specifik inställning är aktiverad:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p>
<?php $debugMode = $this->yellow->system->get("coreDebugMode") ?>
Debug mode is <?php echo htmlspecialchars($debugMode ? "on" : "off") ?>.
</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa core-inställningar:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p>
<?php foreach ($this->yellow->system->getSettings("core") as $key=>$value): ?>
<?php echo htmlspecialchars("$key: $value") ?><br />
<?php endforeach ?>
</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Yellow language
Klassen YellowLanguage
ger tillgång till språkinställningar. Följande metoder är tillgängliga:
getModified
getSettings
getText
getTextHtml
isExisting
isText
setDefaults
setText
Beskrivning av metoder och argument:
language->setDefaults($lines): void
Ställ in standard språkinställningar
language->setText($key, $value, $language): void
Ställ in språkinställning
language->getText($key, $language = ""): string
Returnera språkinställning
language->getTextHtml($key, $language = ""): string
Returnera språkinställning, HTML-kodad
language->getSettings($filterStart = "", $filterEnd = "", $language = ""): array
Returnera språkinställningar
language->getModified($httpFormat = false): int|string
Returnera ändringsdatum för språkinställningar, Unix-tid eller HTTP-format
language->isText($key, $language = ""): bool
Kontrollera om språkinställning finns
language->isExisting($language): bool
Kontrollera om språket finns
Layoutfil för att visa en språkinställning:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p><?php echo $this->yellow->language->getTextHtml("wikiModified") ?>
<?php echo $this->yellow->page->getDateHtml("modified") ?></p>
<?php echo $this->yellow->page->getContent() ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att kontrollera om ett specifikt språk finns:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $found = $this->yellow->language->isExisting("sv") ?>
<p>Swedish language <?php echo htmlspecialchars($found? "" : "not") ?> installed.</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa språk och översättare:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p>
<?php foreach ($this->yellow->system->getAvailable("language") as $language): ?>
<?php echo $this->yellow->language->getTextHtml("languageDescription", $language) ?> -
<?php echo $this->yellow->language->getTextHtml("languageTranslator", $language) ?><br />
<?php endforeach ?>
</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Yellow user
Klassen YellowUser
ger tillgång till användarinställningar. Följande metoder är tillgängliga:
getModified
getSettings
getUser
getUserHtml
isExisting
isUser
remove
save
setUser
Beskrivning av metoder och argument:
user->save($fileName, $email, $settings): bool
Spara användarinställningar i filen
user->remove($fileName, $email): bool
Ta bort användarinställningar från fil
user->setUser($key, $value, $email): void
Ställ in användarinställning
user->getUser($key, $email = ""): string
Returnera användarinställning
user->getUserHtml($key, $email = ""): string
Returnera användarinställning, HTML encoded
user->getSettings($email = ""): array
Returnera användarinställningar
user->getModified($httpFormat = false): int|string
Returnera ändringsdatum för användarinställningar, Unix-tid eller HTTP-format
user->isUser($key, $email = ""): bool
Kontrollera om användarinställning finns
user->isExisting($email): bool
Kontrollera om användaren finns
Layoutfil för att visa den aktuella användaren:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p>
<?php echo "Name: ".$this->yellow->user->getUserHtml("name")."<br />" ?>
<?php echo "Email: ".$this->yellow->user->getUserHtml("email")."<br />" ?>
</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att kontrollera om en användare är inloggad:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $found = $this->yellow->user->isUser("name") ?>
<p>You are <?php echo htmlspecialchars($found? "" : "not") ?> logged in.</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa användare och deras status:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p>
<?php foreach ($this->yellow->system->getAvailable("email") as $email): ?>
<?php echo $this->yellow->user->getUserHtml("name", $email) ?> -
<?php echo $this->yellow->user->getUserHtml("status", $email) ?><br />
<?php endforeach ?>
</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Yellow extension
Klassen YellowExtension
ger tillgång till tillägg. Följande metoder är tillgängliga:
get
getModified
isExisting
Beskrivning av metoder och argument:
extension->get($key): object
Returnera tillägg
extension->getModified($httpFormat = false): int|string
Returnera ändringsdatum för tilläg, Unix-tid eller HTTP-format
extension->isExisting($key): bool
Kontrollera om tilläget finns
Layoutfil för att visa tillägg:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p>
<?php foreach($this->yellow->extension->data as $key=>$value): ?>
<?php echo htmlspecialchars($key." ".$value["version"]) ?><br />
<?php endforeach ?>
</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att kontrollera om ett specifikt tillägg finns:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $found = $this->yellow->extension->isExisting("search") ?>
<p>Search extension <?php echo htmlspecialchars($found ? "" : "not") ?> installed.</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Kod för att anropa en funktion från ett annat tillägg:
if ($this->yellow->extension->isExisting("image")) {
$fileName = "media/images/photo.jpg";
list($src, $width, $height) = $this->yellow->extension->get("image")->getImageInformation($fileName, "100%", "100%");
echo "<img src=\"".htmlspecialchars($src)."\" width=\"".htmlspecialchars($width)."\" height=\"".htmlspecialchars($height)."\" />";
}
Yellow lookup
Klassen YellowLookup
ger tillgång till uppslag och normalisering. Följande metoder är tillgängliga:
findContentLocationFromFile
findFileFromContentLocation
findFileFromMediaLocation
findMediaDirectory
findMediaLocationFromFile
getUrlInformation
isContentFile
isFileLocation
isMediaFile
isSystemFile
isValidFile
normaliseArguments
normaliseArray
normaliseData
normaliseLocation
normaliseName
normalisePath
normaliseUrl
Beskrivning av metoder och argument:
lookup->findContentLocationFromFile($fileName): string
Returnera innehållsplats från filsökvägen
lookup->findFileFromContentLocation($location, $directory = false): string
Returnera filsökväg från innehållsplatsen
lookup->findMediaLocationFromFile($fileName): string
Returnera medieplats från filsökvägen
lookup->findFileFromMediaLocation($location): string
Returnera filsökväg från medieplatsen
lookup->findMediaDirectory($key): string
Returnera mediakatalog från en systeminställning
lookup->normaliseName($text, $removePrefix = false, $removeExtension = false, $filterStrict = false): string
Normalisera namn
toolbox->normaliseData($text, $type = "html", $filterStrict = true): string
Normalisera element och attribut i HTML/SVG-data
lookup->normaliseArray($input): array
Normalisera array, gör nycklar till samma skiftläge
toolbox->normalisePath($text): string
Normalisera relativa sökvägsandelar
lookup->normaliseLocation($location, $pageLocation, $filterStrict = true): string
Normalisera plats, gör absolut plats
toolbox->normaliseArguments($text, $appendSlash = true, $filterStrict = true): string
Normalisera platsargument
lookup->normaliseUrl($scheme, $address, $base, $location, $filterStrict = true): string
Normalisera URL, gör absolut URL
lookup->getUrlInformation($url): string
Returnera URL-information
lookup->isFileLocation($location): bool
Kontrollera om platsen anger fil eller katalog
lookup->isValidFile($fileName): bool
Kontrollera om filen är giltig
lookup->isContentFile($fileName): bool
Kontrollera om innehållsfil
lookup->isMediaFile($fileName): bool
Kontrollera om mediefil
lookup->isSystemFile($fileName): bool
Kontrollera om systemfil
Layoutfil för att visa bildsökvägar:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p>
<?php $pathInstall = $this->system->get("coreServerInstallDirectory") ?>
<?php $pathImages = $this->yellow->lookup->findMediaDirectory("coreImageLocation") ?>
<?php $pathThumbs = $this->yellow->lookup->findMediaDirectory("coreThumbnailLocation") ?>
<?php echo "Image files: ".htmlspecialchars($pathInstall.$pathImages)."<br />" ?>
<?php echo "Image thumbnails: ".htmlspecialchars($pathInstall.$pathThumbs)."<br />" ?>
</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa sidtyp:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $fileLocation = $this->yellow->lookup->isFileLocation($this->yellow->page->location) ?>
<p>Page is <?php echo htmlspecialchars($fileLocation? "file" : "directory") ?>.</p>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Kod för att dela upp en URL:
if (!is_string_empty($url)) {
list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($staticUrl);
echo "Found scheme:$scheme address:$address base:$base\n";
}
Yellow toolbox
Klassen YellowToolbox
ger tillgång till verktygslådan med hjälpfunktioner. Följande metoder är tillgängliga:
appendFile
copyFile
createFile
createTextDescription
deleteDirectory
deleteFile
getCookie
getDirectoryEntries
getDirectoryEntriesRecursive
getFileModified
getFileType
getLocationArguments
getServer
getTextArguments
getTextLines
getTextList
modifyFile
readFile
renameDirectory
renameFile
Beskrivning av metoder och argument:
toolbox->getCookie($key): string
Returnera webbläsarkakan för aktuella HTTP-begäran
toolbox->getServer($key): string
Returnera serverargument för aktuella HTTP-begäran
toolbox->getLocationArguments(): string
Returnera platsargument för aktuella HTTP-begäran
toolbox->getDirectoryEntries($path, $regex = "/.*/", $sort = true, $directories = true, $includePath = true): array
Returnera filer och kataloger
toolbox->getDirectoryEntriesRecursive($path, $regex = "/.*/", $sort = true, $directories = true, $levelMax = 0): array
Returnera filer och kataloger rekursivt
toolbox->readFile($fileName, $sizeMax = 0): string
Läs fil, tom sträng om den inte hittas
toolbox->createFile($fileName, $fileData, $mkdir = false): bool
Skapa fil
toolbox->appendFile($fileName, $fileData, $mkdir = false): bool
Lägg till fil
toolbox->copyFile($fileNameSource, $fileNameDestination, $mkdir = false): bool
Kopiera fil
toolbox->renameFile($fileNameSource, $fileNameDestination, $mkdir = false): bool
Byt namn på en fil
toolbox->renameDirectory($pathSource, $pathDestination, $mkdir = false): bool
Byt namn på en mapp
toolbox->deleteFile($fileName, $pathTrash = ""): bool
Radera fil
toolbox->deleteDirectory($path, $pathTrash = ""): bool
Radera mapp
toolbox->modifyFile($fileName, $modified): bool
Ställ in ändringsdatum för fil/mapp, Unix-tid
toolbox->getFileModified($fileName): int
Returnera ändringsdatum för fil/mapp, Unix-tid
toolbox->getFileType($fileName): string
Returnera filtyp
toolbox->getTextLines($text): array
Returnera rader från text, inklusive radbrytningar
toolbox->getTextList($text, $separator, $size): array
Returnera array med specifik storlek från text
toolbox->getTextArguments($text, $optional = "-", $sizeMin = 9): array
Returnera array med variabel storlek från text, separerade av mellanslag
toolbox->createTextDescription($text, $lengthMax = 0, $removeHtml = true, $endMarker = "", $endMarkerText = ""): string
Skapa textbeskrivning, med eller utan HTML
Kod för att läsa textrader från filen:
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
$fileData = $this->yellow->toolbox->readFile($fileName);
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
echo $line;
}
Kod för att visa filer i en mapp:
$path = $this->yellow->system->get("coreExtensionDirectory");
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, false) as $entry) {
echo "Found file $entry\n";
}
Kod för att ändra text i flera filer:
$path = $this->yellow->system->get("coreContentDirectory");
foreach ($this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/^.*\.md$/", true, false) as $entry) {
$fileData = $fileDataNew = $this->yellow->toolbox->readFile($entry);
$fileDataNew = str_replace("I drink a lot of water", "I drink a lot of coffee", $fileDataNew);
if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($entry, $fileDataNew)) {
$this->yellow->log("error", "Can't write file '$entry'!");
}
}
Yellow page
Klassen YellowPage
ger tillgång till en sidan och dess sidinställningar. Följande metoder är tillgängliga:
error
get
getBase
getChildren
getChildrenRecursive
getContent
getDate
getDateFormatted
getDateFormattedHtml
getDateHtml
getDateRelative
getDateRelativeHtml
getExtra
getHeader
getHtml
getLastModified
getLocation
getModified
getPage
getPages
getParent
getParentTop
getRequest
getRequestHtml
getSiblings
getStatusCode
getUrl
isActive
isAvailable
isCacheable
isError
isExisting
isHeader
isPage
isRequest
isVisible
set
status
Beskrivning av metoder och argument:
page->set($key, $value): void
Ställ in sidinställning
page->get($key): string
Returnera sidinställning
page->getHtml($key): string
Returnera sidinställning, HTML-kodad
page->getDate($key, $format = ""): string
Returnera sidinställning som språkspecifikt datum
page->getDateHtml($key, $format = ""): string
Returnera sidinställning som språkspecifikt datum, HTML-kodad
page->getDateRelative($key, $format = "", $daysLimit = 30): string
Returnera sidinställning som språkspecifikt datum, i förhållande till idag
page->getDateRelativeHtml($key, $format = "", $daysLimit = 30): string
Returnera sidinställning som språkspecifikt datum, i förhållande till idag, HTML-kodad
page->getDateFormatted($key, $format): string
Returnera sidinställning som datum
page->getDateFormattedHtml($key, $format): string
Returnera sidinställning som datum, HTML-kodad
page->getContent($rawFormat = false): string
Returnera sidinnehåll, HTML-kodat eller råformat
page->getParent(): YellowPage|null
Returnera överordnad sida, null om ingen
page->getParentTop($homeFallback = false): YellowPage|null
Returnera överordnad sida på toppnivå, null om ingen
page->getSiblings($showInvisible = false): YellowPageCollection
Returnera page collection med sidor på samma nivå
page->getChildren($showInvisible = false): YellowPageCollection
Returnera page collection med barnsidor
page->getChildrenRecursive($showInvisible = false, $levelMax = 0): YellowPageCollection
Returnera page collection med barnsidor rekursivt
page->getPages($key): YellowPageCollection
Returnera page collection med ytterligare sidor
page->getPage($key): YellowPage
Returnera delad sida
page->getUrl(): string
Returnera sidans URL
page->getBase($multiLanguage = false): string
Returnera sidans bas
page->getLocation($absoluteLocation = false): string
Returnera sidans plats
page->getRequest($key): string
Returnera requestargument av sidan
page->getRequestHtml($key): string
Returnera requestargument av sidan, HTML-kodad
page->getHeader($key): string
Returnera responseheader av sidan
page->getExtra($name): string
Returnera extra data för sidan
page->getModified($httpFormat = false): int|string
Returnera sidans ändringsdatum, Unix-tid eller HTTP-format
page->getLastModified($httpFormat = false): int|string
Returnera sidans senaste ändringsdatum, Unix-tid eller HTTP-format
page->getStatusCode($httpFormat = false): int|string
Returnera sidans statuskod, nummer eller HTTP-format
page->status($statusCode, $location = ""): void
Svara med statuskod, inget sidinnehåll
page->error($statusCode, $errorMessage = ""): void
Svara med felsidan
page->isAvailable(): bool
Kontrollera om sidan är tillgänglig
page->isVisible(): bool
Kontrollera om sidan är synlig
page->isActive(): bool
Kontrollera om sidan ligger inom aktuella HTTP-begäran
page->isCacheable(): bool
Kontrollera om sidan kan cachelagras
page->isError(): bool
Kontrollera om sidan med fel
page->isExisting($key): bool
Kontrollera om sidinställning finns
page->isRequest($key): bool
Kontrollera om requestargument finns
page->isHeader($key): bool
Kontrollera om responseheader finns
page->isPage($key): bool
Kontrollera om delad sida finns
Layoutfil för att visa sidinnehåll:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php echo $this->yellow->page->getContent() ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa sidinnehåll och författare:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p><?php echo $this->yellow->page->getHtml("author") ?></p>
<?php echo $this->yellow->page->getContent() ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa sidinnehåll och modifieringsdatum:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<p><?php echo $this->yellow->page->getDateHtml("modified") ?></p>
<?php echo $this->yellow->page->getContent() ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Yellow page collection
Klassen YellowPageCollection
ger tillgång till flera sidor. Följande metoder är tillgängliga:
append
diff
filter
getFilter
getModified
getPageNext
getPagePrevious
getPaginationCount
getPaginationLocation
getPaginationNext
getPaginationNumber
getPaginationPrevious
intersect
isEmpty
isPagination
limit
match
merge
paginate
prepend
remove
reverse
shuffle
similar
sort
Beskrivning av metoder och argument:
pages->append($page): void
Lägg till sidan till slutet av page collection
pages->prepend($page): void
Placera sidan i början av page collection
pages->remove($page): YellowPageCollection
Ta bort sidan från page collection
pages->filter($key, $value, $exactMatch = true): YellowPageCollection
Filtrera page collection efter sidinställning
pages->match($regex = "/.*/", $filterByLocation = true): YellowPageCollection
Filtrera page collection efter plats eller fil
pages->sort($key, $ascendingOrder = true): YellowPageCollection
Sortera page collection efter sidinställning
pages->similar($page, $ascendingOrder = false): YellowPageCollection
Sortera page collection efter inställningslikhet
pages->merge($input): YellowPageCollection
Beräkna union, lägg till en page collection
pages->intersect($input): YellowPageCollection
Beräkna korsningen, ta bort sidor som inte finns i en annan page collection
pages->diff($input): YellowPageCollection
Beräkna skillnaden, ta bort sidor som finns i en annan page collection
pages->limit($pagesMax): YellowPageCollection
Begränsa antalet sidor i page collection
pages->reverse(): YellowPageCollection
Omvänd page collection
pages->shuffle(): YellowPageCollection
Gör page collection slumpmässig
pages->paginate($limit): YellowPageCollection
Skapa en paginering för page collection
pages->getPaginationNumber(): int
Returnera aktuellt sidnummer i paginering
pages->getPaginationCount(): int
Returnera högsta sidnummer i paginering
pages->getPaginationLocation($absoluteLocation = true, $pageNumber = 1): string
Returnera plats för en sida i paginering
pages->getPaginationPrevious($absoluteLocation = true): string
Returnera plats för föregående sida i paginering
pages->getPaginationNext($absoluteLocation = true): string
Returnera plats för nästa sida i paginering
pages->getPagePrevious($page): YellowPage|null
Returnera föregående sida i page collection, null om ingen
pages->getPageNext($page): YellowPage|null
Returnera nästa sida i page collection, null om ingen
pages->getFilter(): string
Returnera nuvarande sidfilter
pages->getModified($httpFormat = false): int|string
Returnera ändringsdatum för page collection, Unix-tid eller HTTP-format
pages->isPagination(): bool
Kontrollera om det finns en paginering
page->isEmpty(): bool
Kontrollera om page collection är tom
Layoutfil för att visa tre slumpmässiga sidor:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $pages = $this->yellow->content->index()->shuffle()->limit(3) ?>
<?php $this->yellow->page->setLastModified($pages->getModified()) ?>
<ul>
<?php foreach ($pages as $page): ?>
<li><?php echo $page->getHtml("title") ?></li>
<?php endforeach ?>
</ul>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa senaste sidor:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $pages = $this->yellow->content->index()->sort("modified", false) ?>
<?php $this->yellow->page->setLastModified($pages->getModified()) ?>
<ul>
<?php foreach ($pages as $page): ?>
<li><?php echo $page->getHtml("title") ?></li>
<?php endforeach ?>
</ul>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Layoutfil för att visa draftsidor:
<?php $this->yellow->layout("header") ?>
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php $pages = $this->yellow->content->index(true, true)->filter("status", "draft") ?>
<?php $this->yellow->page->setLastModified($pages->getModified()) ?>
<ul>
<?php foreach ($pages as $page): ?>
<li><?php echo $page->getHtml("title") ?></li>
<?php endforeach ?>
</ul>
</div>
</div>
<?php $this->yellow->layout("footer") ?>
Yellow string
Följande funktioner utökar PHP-strängfunktioner och variabelfunktioner:
is_array_empty
is_string_empty
strlenu
strposu
strrposu
strtoloweru
strtoupperu
substru
Beskrivning av funktioner och argument:
strtoloweru($string): string
Konvertera sträng till gemener, UTF-8-kompatibel
strtoupperu($string): string
Konvertera sträng till versaler, UTF-8-kompatibel
strlenu($string): int
+ strlenb($string): int
Returnera stränglängd, UTF-8 tecken eller byte
strposu($string, $search): int|false
+ strposb($string, $search): int|false
Returnera strängposition för första träffen, UTF-8 tecken eller byte
strrposu($string, $search): int|false
+ strrposb($string, $search): int|false
Returnera strängposition för senaste träffen, UTF-8 tecken eller byte
substru($string, $start, $length): string
+ substrb($string, $start, $length): string
Returnera en del av en sträng, UTF-8-tecken eller byte
is_string_empty($string): bool
Kontrollera om strängen är tom
is_array_empty($array): bool
Kontrollera om arrayen är tom
Kod för att konvertera strängar:
$string = "Datenstrom Yellow är för människor som skapar små webbsidor";
echo strtoloweru($string); // datenstrom yellow är för människor som skapar små webbsidor
echo strtoupperu($string); // DATENSTROM YELLOW ÄR FÖR MÄNNISKOR SOM SKAPAR SMÅ WEBBSIDOR
$string = "Text med UTF-8 tecken åäö";
echo strlenu($string); // 25
echo strposu($string, "UTF"); // 9
echo substru($string, -3, 3); // åäö
Kod för att kontrollera om variabler är tomma:
var_dump(is_string_empty("")); // bool(true)
var_dump(is_string_empty("text")); // bool(false)
var_dump(is_string_empty("0")); // bool(false)
var_dump(is_array_empty(array())); // bool(true)
var_dump(is_array_empty(new ArrayObject())); // bool(true)
var_dump(is_array_empty(array("entry"))); // bool(false)
Händelser
Med hjälp av händelser kan hemsidan informera när något händer. Först laddas tilläggen och onLoad
anropas. Så snart alla tillägg har laddats kallas onStartup
. En sida kan hanteras med olika händelser. I de flesta fall genereras sidinnehållet. Om ett fel har inträffat genereras en felsida. Slutligen matas sidan ut och onShutdown
anropas.
Följande händelser är tillgängliga:
onCommand
onCommandHelp
onEditContentFile
onEditMediaFile
onEditSystemFile
onEditUserAccount
onLoad
onLog
onParseContentHtml
onParseContentRaw
onParseContentShortcut
onParseMetaData
onParsePageExtra
onParsePageLayout
onParsePageOutput
onRequest
onShutdown
onStartup
onUpdate
Yellow core händelser
Yellow core händelser meddelar när ett tillstånd ändras:
public function onLoad($yellow)
Hantera initialisering
public function onStartup()
Hantera start
public function onRequest($scheme, $address, $base, $location, $fileName)
Hantera begäran
public function onUpdate($action)
Hantera uppdatering
public function onLog($action, $message)
Hantera loggning
public function onShutdown()
Hantera avstängningen
Tillägg för hantering av initiering:
<?php
class YellowExample {
const VERSION = "0.1.0";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
}
Tillägg för hantering av daglig uppdateringshändelse:
<?php
class YellowExample {
const VERSION = "0.1.1";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle update
public function onUpdate($action) {
if ($action=="daily") {
$this->yellow->log("info", "Handle daily update event");
}
}
}
Yellow parse händelser
Yellow core händelser meddelar när en sida visas:
public function onParseMetaData($page)
Hantera metadata av en sida
public function onParseContentRaw($page, $text)
Hantera sidinnehåll i råformat
public function onParseContentShortcut($page, $name, $text, $type)
Hantera sidinnehåll av förkortning
public function onParseContentHtml($page, $text)
Hantera sidinnehåll i HTML-format
public function onParsePageLayout($page, $name)
Hantera sidlayout
public function onParsePageExtra($page, $name)
Hantera extra data för sidan
public function onParsePageOutput($page, $text)
Hantera output data för sidan
Tillägg för egen förkortning:
<?php
class YellowExample {
const VERSION = "0.1.2";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle page content of shortcut
public function onParseContentShortcut($page, $name, $text, $type) {
$output = null;
if ($name=="example" && ($type=="block" || $type=="inline")) {
$output = "<div class=\"".htmlspecialchars($name)."\">";
$output .= "Add more HTML code here";
$output .= "</div>";
}
return $output;
}
}
Tillägg för egen header:
<?php
class YellowExample {
const VERSION = "0.1.3";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle page extra data
public function onParsePageExtra($page, $name) {
$output = null;
if ($name=="header") {
$extensionLocation = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreExtensionLocation");
$output = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"{$extensionLocation}example.css\" />\n";
$output .= "<script type=\"text/javascript\" defer=\"defer\" src=\"{$extensionLocation}example.js\"></script>\n";
}
return $output;
}
}
Yellow edit händelser
Yellow edit händelser meddelar när en sida redigeras:
public function onEditContentFile($page, $action, $email)
Hantera innehållsfiländringar
public function onEditMediaFile($file, $action, $email)
Hantera mediefiländringar
public function onEditSystemFile($file, $action, $email)
Hantera systemfiländringar
public function onEditUserAccount($action, $email, $password)
Hantera ändringar av användarkonton
Tillägg för hantering av sidredigering:
<?php
class YellowExample {
const VERSION = "0.1.4";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle media file changes
public function onEditContentFile($page, $action, $email) {
if ($action=="edit") {
$title = $page->get("title");
$name = $this->yellow->user->getUser("name", $email);
$this->yellow->log("info", "Edit page by user '".strtok($name, " ")."'");
}
}
}
Tillägg för hantering av filuppladdning:
<?php
class YellowExample {
const VERSION = "0.1.5";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle media file changes
public function onEditMediaFile($file, $action, $email) {
if ($action=="upload") {
$fileName = $file->fileName;
$fileType = $this->yellow->toolbox->getFileType($file->get("fileNameShort"));
$name = $this->yellow->user->getUser("name", $email);
$this->yellow->log("info", "Upload file by user '".strtok($name, " ")."'");
}
}
}
Yellow command händelser
Yellow command händelser när ett kommando körs:
public function onCommand($command, $text)
Hantera kommandon
public function onCommandHelp()
Hantera hjälp för kommandon
Tillägg för eget kommando:
<?php
class YellowExample {
const VERSION = "0.1.6";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle command
public function onCommand($command, $text) {
$statusCode = 0;
if ($command=="example") {
echo "Yellow $command: Add more text here\n";
$statusCode = 200;
}
return $statusCode;
}
// Handle command help
public function onCommandHelp() {
return "example";
}
}
Tillägg för flera egna kommandon:
<?php
class YellowExample {
const VERSION = "0.1.7";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle command
public function onCommand($command, $text) {
switch ($command) {
case "hello": $statusCode = $this->processCommandHello($command, $text); break;
case "goodbye": $statusCode = $this->processCommandGoodbye($command, $text); break;
default: $statusCode = 0;
}
return $statusCode;
}
// Handle command help
public function onCommandHelp() {
return array("hello [name]", "goodbye [name]");
}
// Handle command for hello
public function processCommandHello($command, $text) {
if (is_string_empty($text)) $text = "World";
echo "Hello $text\n";
return 200;
}
// Handle command for goodbye
public function processCommandGoodbye($command, $text) {
if (is_string_empty($text)) $text = "World";
echo "Goodbye $text\n";
return 200;
}
}
Relaterad information
Har du några frågor? Få hjälp.