Tsugi

LessonsLegacyFiles
in package

Legacy /cc/export helper: turn same-server public file URLs into cartridge bytes.

Used by cc/export.php and course copy of a file-based lessons.json. Settings / LessonsCartridge already packages Files-tool blobs and is intentionally separate.

Table of Contents

Constants

FILE_EXTENSIONS  : array<int, string> = array('pdf', 'ppt', 'pptx', 'pps', 'ppsx', 'pot...
Office / document extensions that should travel in the zip as webcontent.
FILEISH_KINDS  : array<int, string> = array('slide', 'reference', 'assignment', 'solu...
Item kinds whose URLs are considered for packing as files.

Properties

$embedFiles  : bool
When false (thin cartridge), same-server files stay web links.
$seen  : array<string, array{identifierref: string, listings: int}>
realpath => array{identifierref:string,listings:int}

Methods

__construct()  : mixed
addToModule()  : string
Add a lessons URL as webcontent when it is a same-server public file; otherwise keep it as an IMS web link.
isSameServer()  : bool
Host (and port) matches $CFG->apphome or $CFG->wwwroot.
looksLikeFile()  : bool
Path looks like a downloadable document (pdf, pptx, …), not a site page.
payloadForUrl()  : array{bytes: string, path: string, filename: string, sha256: string, realpath: string}|null
Local file bytes for a public same-server URL, or null to leave as a link.
summarize()  : array{scanned: int, files: int, listings: int, links: int, paths: list, by_module: array}
Count slide/reference/assignment/solution URLs that will become files vs stay links.
wantsThickCartridge()  : bool
Thick cartridge includes file contents. Default / unknown is thin.
emptySummary()  : array{scanned: int, files: int, listings: int, links: int, paths: list, by_module: array}
isFileishKind()  : bool
mapIfEmbeddable()  : array{realpath: string, path: string, filename: string}|null
mapUrlToLocalFile()  : array{realpath: string, path: string, filename: string}|null
relativePathUnderBase()  : string|null
safeFileUnderRoot()  : string|null
serverBases()  : array<int, array{url: string, root: string}>
apphome maps onto the parent of tsugi (course files). wwwroot maps onto dirroot.
urlIsUnderBase()  : bool
urlPort()  : int
urlsForModule()  : array<int, string>

Constants

FILE_EXTENSIONS

Office / document extensions that should travel in the zip as webcontent.

public array<int, string> FILE_EXTENSIONS = array('pdf', 'ppt', 'pptx', 'pps', 'ppsx', 'pot', 'potx', 'doc', 'docx', 'xls', 'xlsx', 'odt', 'odp', 'ods', 'zip', 'epub', 'rtf', 'txt', 'csv', 'key')

HTML, PHP, and extensionless course pages stay web links.

FILEISH_KINDS

Item kinds whose URLs are considered for packing as files.

public array<int, string> FILEISH_KINDS = array('slide', 'reference', 'assignment', 'solution')

Properties

$embedFiles

When false (thin cartridge), same-server files stay web links.

private bool $embedFiles = false

$seen

realpath => array{identifierref:string,listings:int}

private array<string, array{identifierref: string, listings: int}> $seen = array()

Methods

__construct()

public __construct([bool $embedFiles = false ]) : mixed
Parameters
$embedFiles : bool = false

Thick cartridge includes file bytes

addToModule()

Add a lessons URL as webcontent when it is a same-server public file; otherwise keep it as an IMS web link.

public addToModule(ZipArchive $zip, CC $cc_dom, DOMNode $module, string $title, string $url[, string|null $parentPath = null ][, mixed $lesson = null ]) : string
Parameters
$zip : ZipArchive
$cc_dom : CC
$module : DOMNode
$title : string
$url : string

Absolute URL after expandLink / absolute_url

$parentPath : string|null = null
$lesson : mixed = null

Optional lesson/item for windowTarget and LOM description

Return values
string —

'file', 'listing', or 'url'

isSameServer()

Host (and port) matches $CFG->apphome or $CFG->wwwroot.

public static isSameServer(string $url) : bool
Parameters
$url : string
Return values
bool

looksLikeFile()

Path looks like a downloadable document (pdf, pptx, …), not a site page.

public static looksLikeFile(string $url) : bool
Parameters
$url : string
Return values
bool

payloadForUrl()

Local file bytes for a public same-server URL, or null to leave as a link.

public static payloadForUrl(string $url) : array{bytes: string, path: string, filename: string, sha256: string, realpath: string}|null
Parameters
$url : string
Return values
array{bytes: string, path: string, filename: string, sha256: string, realpath: string}|null

summarize()

Count slide/reference/assignment/solution URLs that will become files vs stay links.

public static summarize(object $l[, array<string|int, mixed>|false $anchors = false ]) : array{scanned: int, files: int, listings: int, links: int, paths: list, by_module: array}

Does not read file bytes.

Parameters
$l : object

Lessons

$anchors : array<string|int, mixed>|false = false
Return values
array{scanned: int, files: int, listings: int, links: int, paths: list, by_module: array}

wantsThickCartridge()

Thick cartridge includes file contents. Default / unknown is thin.

public static wantsThickCartridge(mixed $raw) : bool
Parameters
$raw : mixed

Query value, usually "thin" or "thick"

Return values
bool

emptySummary()

private static emptySummary() : array{scanned: int, files: int, listings: int, links: int, paths: list, by_module: array}
Return values
array{scanned: int, files: int, listings: int, links: int, paths: list, by_module: array}

isFileishKind()

private static isFileishKind(mixed $type, string $kind) : bool
Parameters
$type : mixed
$kind : string
Return values
bool

mapIfEmbeddable()

private static mapIfEmbeddable(string $url) : array{realpath: string, path: string, filename: string}|null
Parameters
$url : string
Return values
array{realpath: string, path: string, filename: string}|null

mapUrlToLocalFile()

private static mapUrlToLocalFile(string $url) : array{realpath: string, path: string, filename: string}|null
Parameters
$url : string
Return values
array{realpath: string, path: string, filename: string}|null

relativePathUnderBase()

private static relativePathUnderBase(string $url, string $base) : string|null
Parameters
$url : string
$base : string
Return values
string|null

safeFileUnderRoot()

private static safeFileUnderRoot(string $candidate, string $root) : string|null
Parameters
$candidate : string
$root : string
Return values
string|null

serverBases()

apphome maps onto the parent of tsugi (course files). wwwroot maps onto dirroot.

private static serverBases() : array<int, array{url: string, root: string}>

Longer URL prefixes first so /course/tsugi/… is not treated as an apphome path.

Return values
array<int, array{url: string, root: string}>

urlIsUnderBase()

private static urlIsUnderBase(string $url, string $base) : bool
Parameters
$url : string
$base : string
Return values
bool

urlPort()

private static urlPort(array<string, mixed> $parts) : int
Parameters
$parts : array<string, mixed>

parse_url() result

Return values
int

urlsForModule()

private static urlsForModule(object $module) : array<int, string>
Parameters
$module : object
Return values
array<int, string>

        
On this page

Search results