ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ilPCSourceCode Class Reference
+ Inheritance diagram for ilPCSourceCode:
+ Collaboration diagram for ilPCSourceCode:

Public Member Functions

 init ()
 Init object. More...
 
 modifyPageContentPostXsl (string $a_output, string $a_mode="presentation", bool $a_abstract_only=false)
 Modify page content after xsl. More...
 
 highlightText (string $a_text, string $proglang)
 Highlights Text with given ProgLang. More...
 
 importFile (string $tmpname)
 
- Public Member Functions inherited from ilPCParagraph
 init ()
 Init object. More...
 
 create (ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="", bool $from_placeholder=false)
 Create paragraph node (incl. More...
 
 setText (string $a_text, bool $a_auto_split=false)
 Set (xml) content of text paragraph. More...
 
 getText (bool $a_short_mode=false)
 Get (xml) content of paragraph. More...
 
 setCharacteristic (string $a_char)
 
 getCharacteristic ()
 
 setSubCharacteristic (string $a_char)
 
 getAutoIndent ()
 
 setAutoIndent (string $ind)
 
 getSubCharacteristic ()
 
 setDownloadTitle (string $title)
 
 getDownloadTitle ()
 
 setShowLineNumbers (string $a_char)
 
 getShowLineNumbers ()
 
 setLanguage (string $a_lang)
 
 getLanguage ()
 
 input2xml (string $a_text, bool $a_wysiwyg=false, bool $a_handle_lists=true)
 
 autoSplit (string $a_text)
 This function splits a paragraph text that has been already processed with input2xml at each header position =header1=, ==header2== or ===header3=== and returns an array that contains the single chunks. More...
 
 handleNextBr (string $a_str)
 Remove preceding
More...
 
 removeTrailingBr (string $a_str)
 Remove trailing
More...
 
 getType ()
 Need to override getType from ilPageContent to distinguish between Pararagraph and Source. More...
 
 saveJS (ilPageObject $a_pg_obj, string $a_content, string $a_char, string $a_pc_id, string $a_insert_at="", bool $from_placeholder=false)
 Save input coming from ajax. More...
 
 getLastSavedPCId (ilPageObject $a_pg_obj, bool $a_as_ajax_str=false)
 Get last inserted pc ids. More...
 
 updatePage (ilPageObject $a_page)
 Update page object (it would be better to have this centralized and to change the constructors and pass the page object instead the dom object) More...
 
 autoLinkGlossaries (array $a_glos)
 
 getJavascriptFiles (string $a_mode)
 
 getOnloadCode (string $a_mode)
 
 getModel ()
 Get model as needed for the front-end editor. More...
 
 insert (\ilPageObject $page, string $a_content, string $a_char, string $a_pc_id, string $a_insert_at="", string $a_new_pc_id="")
 Save input coming from ajax. More...
 
- Public Member Functions inherited from ilPageContent
 __construct (ilPageObject $a_pg_obj, ?PageManagerInterface $page_manager=null, ?ObjectAdapterInterface $object_adapter=null)
 
 setPage (ilPageObject $a_val)
 
 getPage ()
 
 init ()
 Init object. More...
 
 getType ()
 
 getDomNode ()
 
 getDomDoc ()
 
 setDomNode (DOMNode $node)
 
 getChildNode ()
 
 getJavascriptFiles (string $a_mode)
 
 getCssFiles (string $a_mode)
 
 getOnloadCode (string $a_mode)
 
 setHierId (string $a_hier_id)
 
 getHierId ()
 
 lookupHierId ()
 
 readHierId ()
 
 setPcId (string $a_pcid)
 
 getPCId ()
 
 setFileDownloadLink (string $a_download_link)
 
 getFileDownloadLink ()
 
 setProfileBackUrl (string $url)
 
 getProfileBackUrl ()
 
 setFullscreenLink (string $a_fullscreen_link)
 
 getFullscreenLink ()
 
 setSourcecodeDownloadScript (string $script_name)
 
 getSourcecodeDownloadScript ()
 
 readPCId ()
 
 writePCId (string $a_pc_id)
 
 setEnabled (string $value)
 Set Enabled value for page content component. More...
 
 enable ()
 
 disable ()
 
 isEnabled ()
 
 createPageContentNode (bool $a_set_this_node=true)
 Create page content node (always use this method first when adding a new element) More...
 
 getNewPageContentNode ()
 
 modifyPageContentPostXsl (string $a_output, string $a_mode, bool $a_abstract_only=false)
 Modify page content after xsl. More...
 
 getModel ()
 Get model as needed for the front-end editor. More...
 

Static Public Member Functions

static getSupportedLanguages ()
 
static getLangVars ()
 Get lang vars needed for editing. More...
 
- Static Public Member Functions inherited from ilPCParagraph
static attribsToArray (string $a_str)
 converts a string of format var1 = "val1" var2 = "val2" ... into an array More...
 
static _input2xml (string $a_text, string $a_lang, bool $a_wysiwyg=false, bool $a_handle_lists=true)
 Converts user input to xml User input comes as bb code information, e.g. More...
 
static intLinks2xml (string $a_text)
 internal links to xml More...
 
static input2xmlReplaceLists (string $a_text)
 Converts xml from DB to output in edit textarea. More...
 
static xml2outputReplaceLists (string $a_text)
 Replaces

with *. More...

 
static segmentString (string $a_haystack, array $a_needles)
 Segments a string into an array at each position of a substring. More...
 
static xml2output (string $a_text, bool $a_wysiwyg=false, bool $a_replace_lists=true, bool $unmask=true)
 Converts xml from DB to output in edit textarea. More...
 
static handleAjaxContent (string $a_content)
 Handle ajax content. More...
 
static handleAjaxContentPost (string $text)
 Post input2xml handling of ajax content. More...
 
static autoLinkGlossariesPage (ilPageObject $a_page, array $a_terms)
 Auto link glossary of whole page. More...
 
static afterPageUpdate (ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
 After page has been updated (or created) More...
 
static beforePageDelete (ilPageObject $a_page)
 Before page is being deleted. More...
 
static afterPageHistoryEntry (ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
 After page history entry has been created. More...
 
static saveAnchors (ilPageObject $a_page, DOMDocument $a_domdoc)
 Save anchors. More...
 
static _deleteAnchors (string $a_parent_type, int $a_page_id, string $a_page_lang)
 Delete anchors of a page. More...
 
static _saveAnchor (string $a_parent_type, int $a_page_id, string $a_page_lang, string $a_anchor_name)
 Save an anchor. More...
 
static _readAnchors (string $a_parent_type, int $a_page_id, string $a_page_lang="-")
 Read anchors of a page. More...
 
static saveMetaKeywords (ilPageObject $a_page, DOMDocument $a_domdoc)
 save all keywords More...
 
- Static Public Member Functions inherited from ilPageContent
static sortHierIds (array $a_array)
 Sort an array of Hier IDS in ascending order. More...
 
static isGreaterHierId (string $a, string $b)
 Check whether Hier ID $a is greater than Hier ID $b. More...
 
static getLangVars ()
 Get lang vars needed for editing. More...
 
static handleCopiedContent (DOMDocument $a_domdoc, bool $a_self_ass=true, bool $a_clone_mobs=false, int $new_parent_id=0, int $obj_copy_id=0)
 Handle copied content. More...
 
static afterPageUpdate (ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
 After page has been updated (or created) More...
 
static beforePageDelete (ilPageObject $a_page)
 Before page is being deleted. More...
 
static afterRepositoryCopy (ilPageObject $page, array $mapping, int $source_ref_id)
 After repository (container) copy action. More...
 
static afterPageHistoryEntry (ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
 After page history entry has been created. More...
 
static deleteHistoryLowerEqualThan (string $parent_type, int $page_id, string $lang, int $delete_lower_than_nr)
 Overwrite in derived classes, if old history entries are being deleted. More...
 

Data Fields

const string JAVA = "java"
 
const string PHP = "php"
 
const string C = "c"
 
const string CPP = "cpp"
 
const string HTML = "html4strict"
 
const string XML = "xml"
 
const string VISUAL_BASIC = "vb"
 
const string LATEX = "latex"
 
const string DELPHI = "delphi"
 
const string PYTHON = "python"
 
const string CSS = "css"
 
const string JAVASCRIPT = "javascript"
 
const string SQL = "sql"
 
const string BASH = "bash"
 
const string POWERSHELL = "powershell"
 
- Data Fields inherited from ilPageContent
string $hier_id = ""
 
DOMNode $dom_node = null
 
string $page_lang = ""
 

Protected Member Functions

 phikiMap (string $lang)
 
- Protected Member Functions inherited from ilPCParagraph
 createAfter (DomNode $node)
 Create paragraph node (incl. More...
 
 checkTextArray (array $text)
 Check text array. More...
 
- Protected Member Functions inherited from ilPageContent
 getPageManager ()
 
 setType (string $a_type)
 Set Type. More...
 
 hasNode ()
 
 createInitialChildNode (string $hier_id, string $pc_id, string $child, array $child_attributes=[])
 

Static Protected Attributes

static array $langs
 
static array $v51_map
 
- Static Protected Attributes inherited from ilPCParagraph
static array $bb_tags
 

Additional Inherited Members

- Static Protected Member Functions inherited from ilPCParagraph
static getBBMap ()
 Get bb to xml tag map. More...
 
static getXMLTagMap ()
 Get tag to bb map. More...
 
static replaceBBCode (string $a_text, string $a_bb, string $a_tag)
 
static isValidTagContent (string $content)
 
static replaceBBTagByMatching (string $start_tag, string $end_tag, string $xml_tag_name, string $text, array $attribs)
 Transforms [iln...]...[\iln] to <IntLink...>...</IntLink>, if content is valid, otherwise it removes the bb tags. More...
 
static linkTermsInDom (DOMDocument $a_dom, array $a_terms, ?DOMNode $a_par_node=null)
 Link terms in a dom page object in bb style. More...
 
- Protected Attributes inherited from ilPCParagraph
string $inserted_pc_id
 
ilObjUser $user
 
ilLanguage $lng
 
- Protected Attributes inherited from ilPageContent
DOMDocument $dom_doc
 
ILIAS COPage InternalDomainService $domain
 
string $pcid
 
string $type = ""
 
ilPageObject $pg_obj
 
string $file_download_link = ''
 
string $fullscreen_link = ''
 
string $sourcecode_download_script = ''
 
ilLogger $log
 
string $profile_back_url = ""
 
ILIAS COPage Dom DomUtil $dom_util
 
PageManagerInterface $page_manager = null
 
ObjectAdapterInterface $object = null
 

Detailed Description

Definition at line 23 of file class.ilPCSourceCode.php.

Member Function Documentation

◆ getLangVars()

static ilPCSourceCode::getLangVars ( )
static

Get lang vars needed for editing.

Returns
string[] array of lang var keys

Reimplemented from ilPageContent.

Definition at line 86 of file class.ilPCSourceCode.php.

86 : array
87 {
88 return array("ed_insert_code", "pc_code");
89 }

◆ getSupportedLanguages()

static ilPCSourceCode::getSupportedLanguages ( )
static

Definition at line 68 of file class.ilPCSourceCode.php.

68 : array
69 {
70 $langs = array();
71 $map = array_flip(self::$v51_map);
72 foreach (self::$langs as $k => $v) {
73 if (isset($map[$k])) {
74 $k = $map[$k];
75 }
76 $langs[$k] = $v;
77 }
78 return $langs;
79 }

References $langs.

Referenced by ilPCSourceCodeGUI\getProgLangOptions().

+ Here is the caller graph for this function:

◆ highlightText()

ilPCSourceCode::highlightText ( string  $a_text,
string  $proglang 
)

Highlights Text with given ProgLang.

Definition at line 235 of file class.ilPCSourceCode.php.

238 : string {
239 $map = ["php3" => "php",
240 "java122" => "java",
241 "html" => "html4strict"];
242 if (isset($map[$proglang])) {
243 $proglang = $map[$proglang];
244 }
245
246 $phiki = new Phiki();
247 $grammar = $this->phikiMap($proglang);
248 if (!is_null($grammar)) {
249 $a_code = $phiki->codeToHtml(html_entity_decode($a_text), $grammar, Theme::GithubLight);
250 } else {
251 $a_code = $a_text;
252 }
253
254 $a_code = substr($a_code, strpos($a_code, ">") + 1);
255 $a_code = substr($a_code, 0, strrpos($a_code, "<"));
256 return $a_code;
257 }
phikiMap(string $lang)

Referenced by modifyPageContentPostXsl().

+ Here is the caller graph for this function:

◆ importFile()

ilPCSourceCode::importFile ( string  $tmpname)

Definition at line 259 of file class.ilPCSourceCode.php.

259 : void
260 {
261 if ($tmpname !== "") {
262 $tmpfs = $this->domain->filesystem()->temp();
263 $this->setText(
264 $this->input2xml($tmpfs->read($tmpname), 0, false)
265 );
266 $tmpfs->delete($tmpname);
267 }
268 }
input2xml(string $a_text, bool $a_wysiwyg=false, bool $a_handle_lists=true)
setText(string $a_text, bool $a_auto_split=false)
Set (xml) content of text paragraph.

◆ init()

ilPCSourceCode::init ( )

Init object.

This function must be overwritten and at least set the content type.

Reimplemented from ilPCParagraph.

Definition at line 81 of file class.ilPCSourceCode.php.

81 : void
82 {
83 $this->setType("src");
84 }
setType(string $a_type)
Set Type.

References ilPageContent\setType().

+ Here is the call graph for this function:

◆ modifyPageContentPostXsl()

ilPCSourceCode::modifyPageContentPostXsl ( string  $a_output,
string  $a_mode = "presentation",
bool  $a_abstract_only = false 
)

Modify page content after xsl.

Reimplemented from ilPageContent.

Definition at line 91 of file class.ilPCSourceCode.php.

95 : string {
96 $nodes = $this->dom_util->path($this->dom_doc, "//Paragraph");
97 $i = 0;
98 foreach ($nodes as $context_node) {
99 $char = $context_node->getAttribute('Characteristic');
100
101 if ($char !== "Code") {
102 $i++;
103 continue;
104 }
105
106 $n = $context_node->parentNode;
107 $char = $context_node->getAttribute('Characteristic');
108 $subchar = $context_node->getAttribute('SubCharacteristic');
109 $showlinenumbers = $context_node->getAttribute('ShowLineNumbers');
110 $downloadtitle = $context_node->getAttribute('DownloadTitle');
111 $autoindent = $context_node->getAttribute('AutoIndent');
112
113 // get XML Content
114 $content = "";
115 foreach ($context_node->childNodes as $child) {
116 $content .= $this->dom_util->dump($child);
117 }
118
119 while ($context_node->firstChild) {
120 $node_del = $context_node->firstChild;
121 $node_del->parentNode->removeChild($node_del);
122 }
123
124 //$content = str_replace("<br />", "<br/>", utf8_decode($content));
125 $content = str_replace("<br />", "<br/>", $content);
126 $content = str_replace("<br/>", "\n", $content);
127 $rownums = count(explode("\n", $content));
128
129 // see #23028
130 //$plain_content = html_entity_decode($content);
131 $plain_content = $content;
132
133 $plain_content = preg_replace_callback(
134 "/\&#x([1-9a-f]{2});?/is",
135 function ($hit) {
136 return chr(base_convert($hit[1], 16, 10));
137 },
138 $plain_content
139 );
140 $plain_content = preg_replace_callback(
141 "/\&#(\d+);?/is",
142 function ($hit) {
143 return chr($hit[1]);
144 },
145 $plain_content
146 );
147 //$content = utf8_encode($this->highlightText($plain_content, $subchar));
148 if ($subchar === "") {
149 $subchar = "other";
150 }
151 $content = $this->highlightText($plain_content, $subchar);
152
153 $content = str_replace("&amp;lt;", "&lt;", $content);
154 $content = str_replace("&amp;gt;", "&gt;", $content);
155 // $content = str_replace("&", "&amp;", $content);
156 //var_dump($content);
157 $rows = "<tr valign=\"top\">";
158 $rownumbers = "";
159 $linenumbers = "";
160
161 //if we have to show line numbers
162 if (strcmp($showlinenumbers, "y") == 0) {
163 $linenumbers = "<td nowrap=\"nowrap\" class=\"ilc_LineNumbers\" >";
164 $linenumbers .= "<pre class=\"ilc_Code ilc_code_block_Code\"><code>";
165
166 for ($j = 0; $j < $rownums; $j++) {
167 $indentno = strlen($rownums) - strlen($j + 1) + 2;
168 $rownumeration = ($j + 1);
169 $linenumbers .= "<span class=\"ilc_LineNumber\">$rownumeration</span>";
170 if ($j < $rownums - 1) {
171 $linenumbers .= "\n";
172 }
173 }
174 $linenumbers .= "</code></pre>";
175 $linenumbers .= "</td>";
176 }
177
178 $rows .= $linenumbers . "<td class=\"ilc_Sourcecode\"><pre class=\"ilc_Code ilc_code_block_Code\">" . $content . "</pre></td>";
179 $rows .= "</tr>";
180
181 // fix for ie explorer which is not able to produce empty line feeds with <br /><br />;
182 // workaround: add a space after each br.
183 $newcontent = str_replace("\n", "<br/>", $rows);
184 // fix for IE
185 $newcontent = str_replace("<br/><br/>", "<br/> <br/>", $newcontent);
186 // falls drei hintereinander...
187 $newcontent = str_replace("<br/><br/>", "<br/> <br/>", $newcontent);
188
189 // workaround for preventing template engine
190 // from hiding paragraph text that is enclosed
191 // in curly brackets (e.g. "{a}", see ilLMEditorGUI::executeCommand())
192 $newcontent = str_replace("{", "&#123;", $newcontent);
193 $newcontent = str_replace("}", "&#125;", $newcontent);
194
195 $a_output = str_replace("[[[[[Code;" . ($i + 1) . "]]]]]", $newcontent, $a_output);
196
197 if ($a_mode != "presentation" && is_object($this->getPage()->getOfflineHandler())
198 && trim($downloadtitle) != "") {
199 // call code handler for offline versions
200 $this->getPage()->getOfflineHandler()->handleCodeParagraph($this->getPage()->getId(), $i + 1, $downloadtitle, $plain_content);
201 }
202 $i++;
203 }
204
205 return $a_output;
206 }
highlightText(string $a_text, string $proglang)
Highlights Text with given ProgLang.

References ILIAS\Survey\Mode\getId(), ilPageContent\getPage(), and highlightText().

+ Here is the call graph for this function:

◆ phikiMap()

ilPCSourceCode::phikiMap ( string  $lang)
protected

Definition at line 208 of file class.ilPCSourceCode.php.

208 : ?Grammar
209 {
210 $grammar = match ($lang) {
211 "java" => Grammar::Java,
212 "php" => Grammar::Php,
213 "c" => Grammar::C,
214 "cpp" => Grammar::Cpp,
215 "html4strict" => Grammar::Html,
216 "xml" => Grammar::Xml,
217 "vb" => Grammar::Vb,
218 "latex" => Grammar::Latex,
219 "delphi" => Grammar::Pascal,
220 "python" => Grammar::Python,
221 "css" => Grammar::Css,
222 "javascript" => Grammar::Javascript,
223 "sql" => Grammar::Sql,
224 "bash" => Grammar::Shellscript,
225 "powershell" => Grammar::Powershell,
226 default => Grammar::Markdown
227 };
228
229 return $grammar;
230 }

Field Documentation

◆ $langs

array ilPCSourceCode::$langs
staticprotected
Initial value:
= array(
self::BASH => "Bash",
self::C => "C",
self::CPP => "C++",
self::CSS => "CSS",
self::DELPHI => "Delphi",
self::HTML => "HTML",
self::JAVA => "Java",
self::JAVASCRIPT => "Javascript",
self::LATEX => "LaTeX",
self::PHP => "PHP",
self::POWERSHELL => "Powershell",
self::PYTHON => "Python",
self::SQL => "SQL",
self::VISUAL_BASIC => "Visual Basic",
self::XML => "XML"
)

Definition at line 44 of file class.ilPCSourceCode.php.

Referenced by getSupportedLanguages().

◆ $v51_map

array ilPCSourceCode::$v51_map
staticprotected
Initial value:
= array(
"php3" => "php",
"java122" => "java",
"html" => "html4strict"
)

Definition at line 62 of file class.ilPCSourceCode.php.

◆ BASH

const string ilPCSourceCode::BASH = "bash"

Definition at line 38 of file class.ilPCSourceCode.php.

◆ C

const string ilPCSourceCode::C = "c"

Definition at line 27 of file class.ilPCSourceCode.php.

◆ CPP

const string ilPCSourceCode::CPP = "cpp"

Definition at line 28 of file class.ilPCSourceCode.php.

◆ CSS

const string ilPCSourceCode::CSS = "css"

Definition at line 35 of file class.ilPCSourceCode.php.

◆ DELPHI

const string ilPCSourceCode::DELPHI = "delphi"

Definition at line 33 of file class.ilPCSourceCode.php.

◆ HTML

const string ilPCSourceCode::HTML = "html4strict"

Definition at line 29 of file class.ilPCSourceCode.php.

◆ JAVA

const string ilPCSourceCode::JAVA = "java"

Definition at line 25 of file class.ilPCSourceCode.php.

◆ JAVASCRIPT

const string ilPCSourceCode::JAVASCRIPT = "javascript"

Definition at line 36 of file class.ilPCSourceCode.php.

◆ LATEX

const string ilPCSourceCode::LATEX = "latex"

Definition at line 32 of file class.ilPCSourceCode.php.

◆ PHP

const string ilPCSourceCode::PHP = "php"

Definition at line 26 of file class.ilPCSourceCode.php.

◆ POWERSHELL

const string ilPCSourceCode::POWERSHELL = "powershell"

Definition at line 39 of file class.ilPCSourceCode.php.

◆ PYTHON

const string ilPCSourceCode::PYTHON = "python"

Definition at line 34 of file class.ilPCSourceCode.php.

◆ SQL

const string ilPCSourceCode::SQL = "sql"

Definition at line 37 of file class.ilPCSourceCode.php.

◆ VISUAL_BASIC

const string ilPCSourceCode::VISUAL_BASIC = "vb"

Definition at line 31 of file class.ilPCSourceCode.php.

◆ XML

const string ilPCSourceCode::XML = "xml"

Definition at line 30 of file class.ilPCSourceCode.php.


The documentation for this class was generated from the following file: