_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q248900 | PHPMailer.AddrAppend | validation | function AddrAppend($type, $addr) {
$addr_str = $type . ": ";
$addr_str .= $this->AddrFormat($addr[0]);
if(count($addr) > 1)
{
for($i = 1; $i < count($addr); $i++)
$addr_str .= ", " . $this->AddrFormat($addr[$i]);
}
$addr_str .= $this->LE;
return $addr_str;
} | php | {
"resource": ""
} |
q248901 | PHPMailer.AddrFormat | validation | function AddrFormat($addr) {
if(empty($addr[1]))
$formatted = $addr[0];
else
{
$formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
$addr[0] . ">";
}
return $formatted;
} | php | {
"resource": ""
} |
q248902 | PHPMailer.SetWordWrap | validation | function SetWordWrap() {
if($this->WordWrap < 1)
return;
switch($this->message_type)
{
case "alt":
// fall through
case "alt_attachments":
$this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
break;
default:
$this->Body = $this->WrapText($this->Body, $this->WordWrap);
break;
}
} | php | {
"resource": ""
} |
q248903 | PHPMailer.CreateBody | validation | function CreateBody() {
$result = "";
$this->SetWordWrap();
switch($this->message_type)
{
case "alt":
$result .= $this->GetBoundary($this->boundary[1], "",
"text/plain", "");
$result .= $this->EncodeString($this->AltBody, $this->Encoding);
$result .= $this->LE.$this->LE;
$result .= $this->GetBoundary($this->boundary[1], "",
"text/html", "");
$result .= $this->EncodeString($this->Body, $this->Encoding);
$result .= $this->LE.$this->LE;
$result .= $this->EndBoundary($this->boundary[1]);
break;
case "plain":
$result .= $this->EncodeString($this->Body, $this->Encoding);
break;
case "attachments":
$result .= $this->GetBoundary($this->boundary[1], "", "", "");
$result .= $this->EncodeString($this->Body, $this->Encoding);
$result .= $this->LE;
$result .= $this->AttachAll();
break;
case "alt_attachments":
$result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
$result .= sprintf("Content-Type: %s;%s" .
"\tboundary=\"%s\"%s",
"multipart/alternative", $this->LE,
$this->boundary[2], $this->LE.$this->LE);
// Create text body
$result .= $this->GetBoundary($this->boundary[2], "",
"text/plain", "") . $this->LE;
$result .= $this->EncodeString($this->AltBody, $this->Encoding);
$result .= $this->LE.$this->LE;
// Create the HTML body
$result .= $this->GetBoundary($this->boundary[2], "",
"text/html", "") . $this->LE;
$result .= $this->EncodeString($this->Body, $this->Encoding);
$result .= $this->LE.$this->LE;
$result .= $this->EndBoundary($this->boundary[2]);
$result .= $this->AttachAll();
break;
}
if($this->IsError())
$result = "";
return $result;
} | php | {
"resource": ""
} |
q248904 | PHPMailer.AddAttachment | validation | function AddAttachment($path, $name = "", $encoding = "base64",
$type = "application/octet-stream") {
if(!@is_file($path))
{
$this->SetError($this->Lang("file_access") . $path);
return false;
}
$filename = basename($path);
if($name == "")
$name = $filename;
$cur = count($this->attachment);
$this->attachment[$cur][0] = $path;
$this->attachment[$cur][1] = $filename;
$this->attachment[$cur][2] = $name;
$this->attachment[$cur][3] = $encoding;
$this->attachment[$cur][4] = $type;
$this->attachment[$cur][5] = false; // isStringAttachment
$this->attachment[$cur][6] = "attachment";
$this->attachment[$cur][7] = 0;
return true;
} | php | {
"resource": ""
} |
q248905 | PHPMailer.AttachAll | validation | function AttachAll() {
// Return text of body
$mime = array();
// Add all attachments
for($i = 0; $i < count($this->attachment); $i++)
{
// Check for string attachment
$bString = $this->attachment[$i][5];
if ($bString)
$string = $this->attachment[$i][0];
else
$path = $this->attachment[$i][0];
$filename = $this->attachment[$i][1];
$name = $this->attachment[$i][2];
$encoding = $this->attachment[$i][3];
$type = $this->attachment[$i][4];
$disposition = $this->attachment[$i][6];
$cid = $this->attachment[$i][7];
$mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
$mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
$mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
if($disposition == "inline")
$mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
$mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
$disposition, $name, $this->LE.$this->LE);
// Encode as string attachment
if($bString)
{
$mime[] = $this->EncodeString($string, $encoding);
if($this->IsError()) { return ""; }
$mime[] = $this->LE.$this->LE;
}
else
{
$mime[] = $this->EncodeFile($path, $encoding);
if($this->IsError()) { return ""; }
$mime[] = $this->LE.$this->LE;
}
}
$mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
return join("", $mime);
} | php | {
"resource": ""
} |
q248906 | PHPMailer.EncodeFile | validation | function EncodeFile ($path, $encoding = "base64") {
if(!@$fd = fopen($path, "rb"))
{
$this->SetError($this->Lang("file_open") . $path);
return "";
}
$magic_quotes = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
$file_buffer = fread($fd, filesize($path));
$file_buffer = $this->EncodeString($file_buffer, $encoding);
fclose($fd);
set_magic_quotes_runtime($magic_quotes);
return $file_buffer;
} | php | {
"resource": ""
} |
q248907 | PHPMailer.EncodeQP | validation | function EncodeQP ($str) {
$encoded = $this->FixEOL($str);
if (substr($encoded, -(strlen($this->LE))) != $this->LE)
$encoded .= $this->LE;
// Replace every high ascii, control and = characters
$encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
"'='.sprintf('%02X', ord('\\1'))", $encoded);
// Replace every spaces and tabs when it's the last character on a line
$encoded = preg_replace("/([\011\040])".$this->LE."/e",
"'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
// Maximum line length of 76 characters before CRLF (74 + space + '=')
$encoded = $this->WrapText($encoded, 74, true);
return $encoded;
} | php | {
"resource": ""
} |
q248908 | PHPMailer.InlineImageExists | validation | function InlineImageExists() {
$result = false;
for($i = 0; $i < count($this->attachment); $i++)
{
if($this->attachment[$i][6] == "inline")
{
$result = true;
break;
}
}
return $result;
} | php | {
"resource": ""
} |
q248909 | PHPMailer.RFCDate | validation | function RFCDate() {
$tz = date("Z");
$tzs = ($tz < 0) ? "-" : "+";
$tz = abs($tz);
$tz = ($tz/3600)*100 + ($tz%3600)/60;
$result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
return $result;
} | php | {
"resource": ""
} |
q248910 | PHPMailer.ServerVar | validation | function ServerVar($varName) {
global $HTTP_SERVER_VARS;
global $HTTP_ENV_VARS;
if(!isset($_SERVER))
{
$_SERVER = $HTTP_SERVER_VARS;
if(!isset($_SERVER["REMOTE_ADDR"]))
$_SERVER = $HTTP_ENV_VARS; // must be Apache
}
if(isset($_SERVER[$varName]))
return $_SERVER[$varName];
else
return "";
} | php | {
"resource": ""
} |
q248911 | PHPMailer.ServerHostname | validation | function ServerHostname() {
if ($this->Hostname != "")
$result = $this->Hostname;
elseif ($this->ServerVar('SERVER_NAME') != "")
$result = $this->ServerVar('SERVER_NAME');
else
$result = "localhost.localdomain";
return $result;
} | php | {
"resource": ""
} |
q248912 | clsOpenTBS.TbsInitArchive | validation | function TbsInitArchive() {
$TBS =& $this->TBS;
$TBS->OtbsCurrFile = false;
$this->TbsStoreLst = array();
$this->TbsCurrIdx = false;
$this->TbsNoField = array(); // idx of sub-file having no TBS fields
$this->IdxToCheck = array(); // index of files to check
$this->PrevVals = array(); // Previous values for 'mergecell' operator
$this->ExtEquiv = false;
$this->ExtType = false;
$this->OtbsSheetSlidesDelete = array();
$this->OtbsSheetSlidesVisible = array();
$this->OpenDocCharts = false;
$this->OpenDocManif = false;
$this->OpenDoc_SheetSlides = false;
$this->OpenDoc_Styles = false;
$this->OpenXmlRid = false;
$this->OpenXmlCTypes = false;
$this->OpenXmlCharts = false;
$this->OpenXmlSharedStr = false;
$this->OpenXmlSlideLst = false;
$this->OpenXmlSlideMasterLst = false;
$this->MsExcel_Sheets = false;
$this->MsWord_HeaderFooter = false;
$this->Ext_PrepareInfo(); // Set extension information
} | php | {
"resource": ""
} |
q248913 | clsOpenTBS.TbsLoadSubFileAsTemplate | validation | function TbsLoadSubFileAsTemplate($SubFileLst) {
if (!is_array($SubFileLst)) $SubFileLst = array($SubFileLst);
$ok = true;
$TBS = false;
foreach ($SubFileLst as $SubFile) {
$idx = $this->FileGetIdx($SubFile);
if ($idx===false) {
$ok = $this->RaiseError('Cannot load "'.$SubFile.'". The file is not found in the archive "'.$this->ArchFile.'".');
} elseif ($idx!==$this->TbsCurrIdx) {
// Save the current loaded subfile if any
$this->TbsStorePark();
// Load the subfile
if (!is_string($SubFile)) $SubFile = $this->TbsGetFileName($idx);
$this->TbsStoreLoad($idx, $SubFile);
if ($this->LastReadNotStored) {
// Loaded for the first time
if ($TBS===false) {
$this->TbsSwitchMode(true); // Configuration which prevents from other plug-ins when calling LoadTemplate()
$MergeAutoFields = $this->TbsMergeAutoFields();
$TBS =& $this->TBS;
}
if ($this->LastReadComp<=0) { // the contents is not compressed
if ($this->ExtInfo!==false) {
$i = $this->ExtInfo;
$e = $this->ExtEquiv;
if (isset($i['rpl_what'])) {
// auto replace strings in the loaded file
$TBS->Source = str_replace($i['rpl_what'], $i['rpl_with'], $TBS->Source);
}
if (($e==='odt') && $TBS->OtbsClearWriter) {
$this->OpenDoc_CleanRsID($TBS->Source);
}
if (($e==='ods') && $TBS->OtbsMsExcelCompatibility) {
$this->OpenDoc_MsExcelCompatibility($TBS->Source);
}
if ($e==='docx') {
if ($TBS->OtbsSpacePreserve) $this->MsWord_CleanSpacePreserve($TBS->Source);
if ($TBS->OtbsClearMsWord) $this->MsWord_Clean($TBS->Source);
}
if (($e==='pptx') && $TBS->OtbsClearMsPowerpoint) {
$this->MsPowerpoint_Clean($TBS->Source);
}
if (($e==='xlsx') && $TBS->OtbsMsExcelConsistent) {
$this->MsExcel_DeleteFormulaResults($TBS->Source);
$this->MsExcel_ConvertToRelative($TBS->Source);
}
}
// apply default TBS behaviors on the uncompressed content: other plug-ins + [onload] fields
if ($MergeAutoFields) $TBS->LoadTemplate(null,'+');
}
}
}
}
if ($TBS!==false) $this->TbsSwitchMode(false); // Reactivate default configuration
return $ok;
} | php | {
"resource": ""
} |
q248914 | clsOpenTBS.TbsStorePark | validation | function TbsStorePark() {
if ($this->TbsCurrIdx!==false) {
$this->TbsStoreLst[$this->TbsCurrIdx] = array('src'=>$this->TBS->Source, 'onshow'=>true);
$this->TBS->Source = '';
$this->TbsCurrIdx = false;
}
} | php | {
"resource": ""
} |
q248915 | clsOpenTBS.TbsStoreLoad | validation | function TbsStoreLoad($idx, $file=false) {
$this->TBS->Source = $this->TbsStoreGet($idx, false);
$this->TbsCurrIdx = $idx;
if ($file===false) $file = $this->TbsGetFileName($idx);
$this->TBS->OtbsCurrFile = $file;
} | php | {
"resource": ""
} |
q248916 | clsOpenTBS.TbsStoreGet | validation | function TbsStoreGet($idx, $caller) {
$this->LastReadNotStored = false;
if ($idx===$this->TbsCurrIdx) {
return $this->TBS->Source;
} elseif (isset($this->TbsStoreLst[$idx])) {
$txt = $this->TbsStoreLst[$idx]['src'];
if ($caller===false) $this->TbsStoreLst[$idx]['src'] = ''; // save memory space
return $txt;
} else {
$this->LastReadNotStored = true;
$txt = $this->FileRead($idx, true);
if ($this->LastReadComp>0) {
if ($caller===false) {
return $txt; // return the uncompressed contents
} else {
return $this->RaiseError("(".$caller.") unable to uncompress '".$this->TbsGetFileName($idx)."'.");
}
} else {
return $txt;
}
}
} | php | {
"resource": ""
} |
q248917 | clsOpenTBS.TbsQuickLoad | validation | function TbsQuickLoad($NameLst) {
if (!is_array($NameLst)) $NameLst = array($NameLst);
$nbr = 0;
$TBS = &$this->TBS;
foreach ($NameLst as $FileName) {
$idx = $this->FileGetIdx($FileName);
if ( (!isset($this->TbsStoreLst[$idx])) && (!isset($this->TbsNoField[$idx])) ) {
$txt = $this->FileRead($idx, true);
if (strpos($txt, $TBS->_ChrOpen)!==false) {
// merge
$nbr++;
if ($nbr==1) {
$MergeAutoFields = $this->TbsMergeAutoFields();
$SaveIdx = $this->TbsCurrIdx; // save the index of sub-file before the QuickLoad
$SaveName = $TBS->OtbsCurrFile;
$this->TbsSwitchMode(true);
}
$this->TbsStorePark(); // save the current file in the store
$TBS->Source = $txt;
unset($txt);
$TBS->OtbsCurrFile = $FileName; // may be needed for [onload] parameters
$this->TbsCurrIdx = $idx;
if ($MergeAutoFields) $TBS->LoadTemplate(null,'+');
} else {
$this->TbsNoField[$idx] = true;
}
}
}
if ($nbr>0) {
$this->TbsSwitchMode(false);
$this->TbsStorePark(); // save the current file in the store
$this->TbsStoreLoad($SaveIdx, $SaveName); // restore the sub-file as before the QuickLoad
}
return $nbr;
} | php | {
"resource": ""
} |
q248918 | clsOpenTBS.TbsSearchInFiles | validation | function TbsSearchInFiles($files, $str, $returnFirstFound = true) {
$keys_ok = array();
// transform the list of files into a list of available idx
$keys_todo = array();
$idx_keys = array();
foreach($files as $k=>$f) {
$idx = $this->FileGetIdx($f);
if ($idx!==false) {
$keys_todo[$k] = $idx;
$idx_keys[$idx] = $k;
}
}
// Search in the current sub-file
if ( ($this->TbsCurrIdx!==false) && isset($idx_keys[$this->TbsCurrIdx]) ) {
$key = $idx_keys[$this->TbsCurrIdx];
$p = strpos($this->TBS->Source, $str);
if ($p!==false) {
$keys_ok[] = array('key' => $key, 'idx' => $this->TbsCurrIdx, 'src' => &$this->TBS->Source, 'pos' => $p, 'curr'=>true);
if ($returnFirstFound) return $keys_ok[0];
}
unset($keys_todo[$key]);
}
// Search in the store
foreach($this->TbsStoreLst as $idx => $s) {
if ( ($idx!==$this->TbsCurrIdx) && isset($idx_keys[$idx]) ) {
$key = $idx_keys[$idx];
$p = strpos($s['src'], $str);
if ($p!==false) {
$keys_ok[] = array('key' => $key, 'idx' => $idx, 'src' => &$s['src'], 'pos' => $p, 'curr'=>false);
if ($returnFirstFound) return $keys_ok[0];
}
unset($keys_todo[$key]);
}
}
// Search in other sub-files (never opened)
foreach ($keys_todo as $key => $idx) {
$txt = $this->FileRead($idx);
$p = strpos($txt, $str);
if ($p!==false) {
$keys_ok[] = array('key' => $key, 'idx' => $idx, 'src' => $txt, 'pos' => $p, 'curr'=>false);
if ($returnFirstFound) return $keys_ok[0];
}
}
if ($returnFirstFound) {
return array('key'=>false, 'idx'=>false, 'src'=>false, 'pos'=>false, 'curr'=>false);
} else {
return $keys_ok;
}
} | php | {
"resource": ""
} |
q248919 | clsOpenTBS.TbsSheetCheck | validation | function TbsSheetCheck() {
if (count($this->OtbsSheetSlidesDelete)>0) $this->RaiseError("Unable to delete the following sheets because they are not found in the workbook: ".(str_replace(array('i:','n:'),'',implode(', ',$this->OtbsSheetSlidesDelete))).'.');
if (count($this->OtbsSheetSlidesVisible)>0) $this->RaiseError("Unable to change visibility of the following sheets because they are not found in the workbook: ".(str_replace(array('i:','n:'),'',implode(', ',array_keys($this->OtbsSheetSlidesVisible)))).'.');
} | php | {
"resource": ""
} |
q248920 | clsOpenTBS.TbsMergeVarFields | validation | function TbsMergeVarFields($PrmVal, $FldVal) {
$this->TBS->meth_Merge_AutoVar($PrmVal, true);
$PrmVal = str_replace($this->TBS->_ChrVal, $FldVal, $PrmVal);
return $PrmVal;
} | php | {
"resource": ""
} |
q248921 | clsOpenTBS.TbsSheetSlide_DeleteDisplay | validation | function TbsSheetSlide_DeleteDisplay($id_or_name, $ok, $delete) {
if (is_null($ok)) $ok = true; // default value
$ext = $this->ExtEquiv;
$ok = (boolean) $ok;
if (!is_array($id_or_name)) $id_or_name = array($id_or_name);
foreach ($id_or_name as $item=>$action) {
if (!is_bool($action)) {
$item = $action;
$action = $ok;
}
$item_ref = (is_string($item)) ? 'n:'.htmlspecialchars($item) : 'i:'.$item; // help to make the difference beetween id and name
if ($delete) {
if ($ok) {
$this->OtbsSheetSlidesDelete[$item_ref] = $item;
} else {
unset($this->OtbsSheetSlidesVisible[$item_ref]);
}
} else {
$this->OtbsSheetSlidesVisible[$item_ref] = $ok;
}
}
} | php | {
"resource": ""
} |
q248922 | clsOpenTBS.TbsPrepareMergeCell | validation | function TbsPrepareMergeCell(&$Txt, &$Loc) {
if ($this->ExtEquiv=='docx') {
// Move the locator just inside the <w:tcPr> element.
// See OnOperation() for other process
$xml = clsTbsXmlLoc::FindStartTag($Txt, 'w:tcPr', $Loc->PosBeg, false);
if ($xml) {
$Txt = substr_replace($Txt, '', $Loc->PosBeg, $Loc->PosEnd - $Loc->PosBeg + 1);
$Loc->PosBeg = $xml->PosEnd+1;
$Loc->PosEnd = $xml->PosEnd;
$this->PrevVals[$Loc->FullName] = ''; // the previous value is saved in property because they can be several sections, and thus several Loc for the same column.
//$Loc->Prms['strconv']='no'; // should work
$Loc->ConvStr=false;
}
}
} | php | {
"resource": ""
} |
q248923 | clsOpenTBS.Ext_DeductFormat | validation | function Ext_DeductFormat(&$Ext, $Search) {
if (strpos(',odt,ods,odg,odf,odp,odm,ott,ots,otg,otp,', ',' . $Ext . ',') !== false) return 'odf';
if (strpos(',docx,xlsx,xlsm,pptx,', ',' . $Ext . ',') !== false) return 'openxml';
if (!$Search) return false;
if ($this->FileExists('content.xml')) {
// OpenOffice documents
if ($this->FileExists('META-INF/manifest.xml')) {
$Ext = '?'; // not needed for processing OpenOffice documents
return 'odf';
}
} elseif ($this->FileExists('[Content_Types].xml')) {
// Ms Office documents
if ($this->FileExists('word/document.xml')) {
$Ext = 'docx';
return 'openxml';
} elseif ($this->FileExists('xl/workbook.xml')) {
$Ext = 'xlsx';
return 'openxml';
} elseif ($this->FileExists('ppt/presentation.xml')) {
$Ext = 'pptx';
return 'openxml';
}
}
return false;
} | php | {
"resource": ""
} |
q248924 | clsOpenTBS.Ext_GetMainIdx | validation | function Ext_GetMainIdx() {
if ( ($this->ExtInfo!==false) && isset($this->ExtInfo['main']) ) {
return $this->FileGetIdx($this->ExtInfo['main']);
} else {
return false;
}
} | php | {
"resource": ""
} |
q248925 | clsOpenTBS.XML_DeleteElements | validation | function XML_DeleteElements(&$Txt, $TagLst, $OnlyInner=false) {
$nbr_del = 0;
foreach ($TagLst as $tag) {
$t_open = '<'.$tag;
$t_close = '</'.$tag;
$p1 = 0;
while (($p1=$this->XML_FoundTagStart($Txt, $t_open, $p1))!==false) {
// get the end of the tag
$pe1 = strpos($Txt, '>', $p1);
if ($pe1===false) return false; // error in the XML formating
$p2 = false;
if (substr($Txt, $pe1-1, 1)=='/') {
$pe2 = $pe1;
} else {
// it's an opening+closing
$p2 = $this->XML_FoundTagStart($Txt, $t_close, $pe1);
if ($p2===false) return false; // error in the XML formating
$pe2 = strpos($Txt, '>', $p2);
}
if ($pe2===false) return false; // error in the XML formating
// delete the tag
if ($OnlyInner) {
if ($p2!==false) $Txt = substr_replace($Txt, '', $pe1+1, $p2-$pe1-1);
$p1 = $pe1; // for next search
} else {
$Txt = substr_replace($Txt, '', $p1, $pe2-$p1+1);
}
}
}
return $nbr_del;
} | php | {
"resource": ""
} |
q248926 | clsOpenTBS.XML_DeleteColumnElements | validation | function XML_DeleteColumnElements(&$Txt, $Tag, $SpanAtt, $ColLst, $ColMax) {
$ColNum = 0;
$ColPos = 0;
$ColQty = 1;
$Continue = true;
$ModifNbr = 0;
while ($Continue && ($Loc = clsTbsXmlLoc::FindElement($Txt, $Tag, $ColPos, true)) ) {
// get colmun quantity covered by the element (1 by default)
if ($SpanAtt!==false) {
$ColQty = $Loc->GetAttLazy($SpanAtt);
$ColQty = ($ColQty===false) ? 1 : intval($ColQty);
}
// count column to keep
$KeepQty = 0;
for ($i=1; $i<=$ColQty ;$i++) {
if (array_search($ColNum+$i, $ColLst)===false) $KeepQty++;
}
if ($KeepQty==0) {
// delete the tag
$Loc->ReplaceSrc('');
$ModifNbr++;
} else {
if ($KeepQty!=$ColQty) {
// edit the attribute
$Loc->ReplaceAtt($SpanAtt, $KeepQty);
$ModifNbr++;
}
$ColPos = $Loc->PosEnd + 1;
}
$ColNum += $ColQty;
if ($ColNum>$ColMax) $Continue = false;
}
return $ModifNbr;
} | php | {
"resource": ""
} |
q248927 | clsOpenTBS.Misc_ColNum | validation | function Misc_ColNum($ColRef, $IsODF) {
if ($IsODF) {
$p = strpos($ColRef, '.');
if ($p!==false) $ColRef = substr($ColRef, $p); // delete the table name wich is in prefix
$ColRef = str_replace( array('.','$'), '', $ColRef);
$ColRef = explode(':', $ColRef);
$ColRef = $ColRef[0];
}
$num = 0;
$rank = 0;
for ($i=strlen($ColRef)-1;$i>=0;$i--) {
$l = $ColRef[$i];
if (!is_numeric($l)) {
$l = ord(strtoupper($l)) -64;
if ($l>0 && $l<27) {
$num = $num + $l*pow(26,$rank);
} else {
return $this->RaiseError('(Sheet) Reference of cell \''.$ColRef.'\' cannot be recognized.');
}
$rank++;
}
}
return $num;
} | php | {
"resource": ""
} |
q248928 | clsOpenTBS.Misc_CellRef | validation | function Misc_CellRef($Col, $Row) {
$r = '';
$x = $Col;
do {
$x = $x - 1;
$c = ($x % 26);
$x = ($x - $c)/26;
$r = chr(65 + $c) . $r; // chr(65)='A'
} while ($x>0);
return $r.$Row;
} | php | {
"resource": ""
} |
q248929 | clsOpenTBS.OpenXML_Rels_ReplaceTarget | validation | function OpenXML_Rels_ReplaceTarget($RelsPath, $OldTarget, $NewTarget) {
$idx = $this->FileGetIdx($RelsPath);
if ($idx===false) $this->RaiseError("Cannot edit target in '$RelsPath' because the file is not found.");
$txt = $this->TbsStoreGet($idx, 'Replace target in rels file');
$att = 'Target="'.$OldTarget.'"';
$loc = clsTbsXmlLoc::FindStartTagHavingAtt($txt, $att, 0);
if ($loc) {
if ($NewTarget === false) {
$loc->Delete();
} else {
$loc->ReplaceAtt('Target',$NewTarget);
}
$this->TbsStorePut($idx, $txt);
return true;
} else {
return false;
}
} | php | {
"resource": ""
} |
q248930 | clsOpenTBS.OpenXML_CTypesPrepareExt | validation | function OpenXML_CTypesPrepareExt($FileOrExt, $ct='') {
$ext = $this->Misc_FileExt($FileOrExt);
$this->OpenXML_CTypesInit();
$lst =& $this->OpenXmlCTypes['Extension'];
if (isset($lst[$ext]) && ($lst[$ext]!=='') ) return;
if (($ct==='') && isset($this->ExtInfo['pic_ext'][$ext])) $ct = 'image/'.$this->ExtInfo['pic_ext'][$ext];
$lst[$ext] = $ct;
} | php | {
"resource": ""
} |
q248931 | clsOpenTBS.OpenXML_ChartGetInfoFromFile | validation | function OpenXML_ChartGetInfoFromFile($idx, $Txt=false) {
if ($idx===false) return false;
$file = $this->CdFileLst[$idx]['v_name'];
$relative = (substr_count($file, '/')==1) ? '' : '../';
$o = $this->OpenXML_Rels_GetObj($file, $relative.'charts/');
if ($o->ChartLst===false) {
if ($Txt===false) $Txt = $this->TbsStoreGet($idx, 'OpenXML_ChartGetInfoFromFile');
$o->ChartLst = array();
$p = 0;
while ($t = clsTbsXmlLoc::FindStartTag($Txt, 'c:chart', $p)) {
$rid = $t->GetAttLazy('r:id');
$name = false;
$title = false;
$descr = false;
$parent = clsTbsXmlLoc::FindStartTag($Txt, 'wp:inline', $t->PosBeg, false); // docx
if ($parent===false) $parent = clsTbsXmlLoc::FindStartTag($Txt, 'p:nvGraphicFramePr', $t->PosBeg, false); // pptx
if ($parent!==false) {
$parent->FindEndTag();
$src = $parent->GetInnerSrc();
$el = clsTbsXmlLoc::FindStartTagHavingAtt($src, 'title', 0);
if ($el!==false) $title = $el->GetAttLazy('title');
$el = clsTbsXmlLoc::FindStartTagHavingAtt($src, 'descr', 0);
if ($el!==false) $descr = $el->GetAttLazy('descr');
}
if (isset($o->TargetLst[$rid])) {
$name = basename($o->TargetLst[$rid]);
if (substr($name,-4)==='.xml') $name = substr($name,0,strlen($name)-4);
}
$o->ChartLst[] = array('rid'=>$rid, 'title'=>$title, 'descr'=>$descr, 'name'=>$name);
$p = $t->PosEnd;
}
}
return $o->ChartLst;
} | php | {
"resource": ""
} |
q248932 | clsOpenTBS.OpenMXL_GarbageCollector | validation | function OpenMXL_GarbageCollector() {
if ( (count($this->IdxToCheck)==0) && (count($this->OtbsSheetSlidesDelete)==0) ) return;
// Key for Pictures
$pic_path = $this->ExtInfo['pic_path'];
$pic_path_len = strlen($pic_path);
// Key for Rels
$rels_ext = '.rels';
$rels_ext_len = strlen($rels_ext);
// List all Pictures and Rels files
$pictures = array();
$rels = array();
foreach ($this->CdFileLst as $idx=>$f) {
$n = $f['v_name'];
if (substr($n, 0, $pic_path_len)==$pic_path) {
$short = basename($pic_path).'/'.basename($n);
$pictures[] = array('name'=>$n, 'idx'=>$idx, 'nbr'=>0, 'short'=>$short);
} elseif (substr($n, -$rels_ext_len)==$rels_ext) {
if ($this->FileGetState($idx)!='d') $rels[$n] = $idx;
}
}
// Read contents or Rels files
foreach ($rels as $n=>$idx) {
$txt = $this->TbsStoreGet($idx, 'GarbageCollector');
foreach ($pictures as $i=>$info) {
if (strpos($txt, $info['short'].'"')!==false) $pictures[$i]['nbr']++;
}
}
// Delete unused Picture files
foreach ($pictures as $info) {
if ($info['nbr']==0) $this->FileReplace($info['idx'], false);
}
} | php | {
"resource": ""
} |
q248933 | clsOpenTBS.MsExcel_ConvertToExplicit_Item | validation | function MsExcel_ConvertToExplicit_Item(&$Txt, $Tag, $Att, $CellRow) {
$tag_pc = strlen($Tag) + 1;
$rpl = '<'.$Tag.' '.$Att.'="';
$rpl_len = strlen($rpl);
$rpl_nbr = 0;
$p = 0;
$empty_first_pos = false;
$empty_nbr = 0;
$item_num = 0;
$rpl_nbr = 0;
while (($p=clsTinyButStrong::f_Xml_FindTagStart($Txt, $Tag, true, $p, true, true))!==false) {
$item_num++;
if ($empty_first_pos===false) $empty_first_pos = $p;
$p = $p + $tag_pc;
if (substr($Txt, $p, 1) == '/') {
// It's an empty item
$empty_nbr++;
} else {
// The item is not empty => relace attribute and delete the previus empty item in the same time
$ref = ($CellRow===false) ? $item_num : $this->Misc_CellRef($item_num, $CellRow);
$x = $rpl.$ref.'"';
$len = $p - $empty_first_pos;
$Txt = substr_replace($Txt, $x, $empty_first_pos, $len);
$rpl_nbr++;
// If it's a row => search for cells
if ($CellRow===false) {
$loc = new clsTbsXmlLoc($Txt, $Tag, $p);
$loc->FindEndTag();
$src = $loc->GetSrc();
$nbr = $this->MsExcel_ConvertToExplicit_Item($src, 'c', 'r', $item_num);
if ($nbr>0) {
$loc->ReplaceSrc($src);
}
$p = $loc->PosEnd;
} else {
$p = $empty_first_pos + $tag_pc;
}
// Ini variables
$empty_nbr = 0;
$empty_first_pos = false;
}
}
return $rpl_nbr;
} | php | {
"resource": ""
} |
q248934 | clsOpenTBS.MsExcel_SheetIsIt | validation | function MsExcel_SheetIsIt($FileName) {
$this->MsExcel_SheetInit();
foreach($this->MsExcel_Sheets as $o) {
if ($FileName=='xl/'.$o->file) return true;
}
return false;
} | php | {
"resource": ""
} |
q248935 | clsOpenTBS.MsExcel_GetDrawingLst | validation | function MsExcel_GetDrawingLst() {
$lst = array();
$dir = '../drawings/';
$dir_len = strlen($dir);
$o = $this->OpenXML_Rels_GetObj($this->TBS->OtbsCurrFile, $dir);
foreach($o->TargetLst as $t) {
if ( (substr($t, 0, $dir_len)===$dir) && (substr($t, -4)==='.xml') ) $lst[] = 'xl/drawings/'.substr($t, $dir_len);
}
return $lst;
} | php | {
"resource": ""
} |
q248936 | clsOpenTBS.MsPowerpoint_InitSlideLst | validation | function MsPowerpoint_InitSlideLst($Master = false) {
if ($Master) {
$RefLst = &$this->OpenXmlSlideMasterLst;
} else {
$RefLst = &$this->OpenXmlSlideLst;
}
if ($RefLst!==false) return $RefLst;
$PresFile = 'ppt/presentation.xml';
$prefix = ($Master) ? 'slideMasters/' : 'slides/';
$o = $this->OpenXML_Rels_GetObj('ppt/presentation.xml', $prefix);
$Txt = $this->FileRead($PresFile);
if ($Txt===false) return false;
$p = 0;
$i = 0;
$lst = array();
$tag = ($Master) ? 'p:sldMasterId' : 'p:sldId';
while ($loc = clsTbsXmlLoc::FindStartTag($Txt, $tag, $p)) {
$i++;
$rid = $loc->GetAttLazy('r:id');
if ($rid===false) {
$this->RaiseError("(Init Slide List) attribute 'r:id' is missing for slide #$i in '$PresFile'.");
} elseif (isset($o->TargetLst[$rid])) {
$f = 'ppt/'.$o->TargetLst[$rid];
$lst[] = array('file' => $f, 'idx' => $this->FileGetIdx($f), 'rid' => $rid);
} else {
$this->RaiseError("(Init Slide List) Slide corresponding to rid=$rid is not found in the Rels file of '$PresFile'.");
}
$p = $loc->PosEnd;
}
$RefLst = $lst;
return $RefLst;
} | php | {
"resource": ""
} |
q248937 | clsOpenTBS.MsPowerpoint_Clean | validation | function MsPowerpoint_Clean(&$Txt) {
$this->MsPowerpoint_CleanRpr($Txt, 'a:rPr');
$Txt = str_replace('<a:rPr/>', '', $Txt);
$this->MsPowerpoint_CleanRpr($Txt, 'a:endParaRPr');
$Txt = str_replace('<a:endParaRPr/>', '', $Txt); // do not delete, can change layout
// join split elements
$Txt = str_replace('</a:t><a:t>', '', $Txt);
$Txt = str_replace('</a:t></a:r><a:r><a:t>', '', $Txt); // this join TBS split tags
// delete empty elements
$Txt = str_replace('<a:t></a:t>', '', $Txt);
$Txt = str_replace('<a:r></a:r>', '', $Txt);
} | php | {
"resource": ""
} |
q248938 | clsOpenTBS.MsPowerpoint_SearchInSlides | validation | function MsPowerpoint_SearchInSlides($str, $returnFirstFound = true) {
// init the list of slides
$this->MsPowerpoint_InitSlideLst(); // List of slides
// build the list of files in the expected structure
$files = array();
foreach($this->OpenXmlSlideLst as $i=>$s) $files[$i+1] = $s['idx'];
// search
$find = $this->TbsSearchInFiles($files, $str, $returnFirstFound);
return $find;
} | php | {
"resource": ""
} |
q248939 | clsOpenTBS.MsPowerpoint_SlideIsIt | validation | function MsPowerpoint_SlideIsIt($FileName) {
$this->MsPowerpoint_InitSlideLst();
foreach ($this->OpenXmlSlideLst as $i => $s) {
if ($FileName==$s['file']) return true;
}
return false;
} | php | {
"resource": ""
} |
q248940 | clsOpenTBS.MsWord_Clean | validation | function MsWord_Clean(&$Txt) {
$Txt = str_replace('<w:lastRenderedPageBreak/>', '', $Txt); // faster
$this->XML_DeleteElements($Txt, array('w:proofErr', 'w:noProof', 'w:lang', 'w:lastRenderedPageBreak'));
$this->MsWord_CleanSystemBookmarks($Txt);
$this->MsWord_CleanRsID($Txt);
$this->MsWord_CleanDuplicatedLayout($Txt);
} | php | {
"resource": ""
} |
q248941 | clsOpenTBS.MsWord_InitHeaderFooter | validation | function MsWord_InitHeaderFooter() {
if ($this->MsWord_HeaderFooter!==false) return;
$types_ok = array('default' => true, 'first' => false, 'even' => false);
// Is there a different header/footer for odd an even pages ?
$idx = $this->FileGetIdx('word/settings.xml');
if ($idx!==false) {
$Txt = $this->TbsStoreGet($idx, 'GetHeaderFooterFile');
$types_ok['even'] = (strpos($Txt, '<w:evenAndOddHeaders/>')!==false);
unset($Txt);
}
// Is there a different header/footer for the first page ?
$idx = $this->FileGetIdx('word/document.xml');
if ($idx===false) return false;
$Txt = $this->TbsStoreGet($idx, 'GetHeaderFooterFile');
$types_ok['first'] = (strpos($Txt, '<w:titlePg/>')!==false);
$places = array('header', 'footer');
$files = array();
$rels = $this->OpenXML_Rels_GetObj('word/document.xml', '');
foreach ($places as $place) {
$p = 0;
$entity = 'w:' . $place . 'Reference';
while ($loc = clsTbsXmlLoc::FindStartTag($Txt, $entity, $p)) {
$p = $loc->PosEnd;
$type = $loc->GetAttLazy('w:type');
if (isset($types_ok[$type]) && $types_ok[$type]) {
$rid = $loc->GetAttLazy('r:id');
if (isset($rels->TargetLst[$rid])) {
$target = $rels->TargetLst[$rid];
$files[] = array('file' => ('word/'.$target), 'type' => $type, 'place' => $place);
}
}
}
}
$this->MsWord_HeaderFooter = $files;
} | php | {
"resource": ""
} |
q248942 | clsOpenTBS.OpenDoc_GetPage | validation | function OpenDoc_GetPage($Tag, $Txt, $Pos, $Forward, $LevelStop) {
$this->OpenDoc_StylesInit();
$p = $Pos;
while ( ($loc = clsTbsXmlLoc::FindStartTagHavingAtt($Txt, 'text:style-name', $p, $Forward))!==false) {
$style = $loc->GetAttLazy('text:style-name');
if ( ($style!==false) && isset($this->OpenDoc_Styles[$style]) ) {
$pbreak = $this->OpenDoc_Styles[$style]->pbreak;
if ($pbreak!==false) {
if ($Forward) {
// Forward
if ($pbreak==='before') {
return $loc->PosBeg -1; // note that the page-break is not in the block
} else {
$loc->FindEndTag();
return $loc->PosEnd;
}
} else {
// Backward
if ($pbreak==='before') {
return $loc->PosBeg;
} else {
$loc->FindEndTag();
return $loc->PosEnd+1; // note that the page-break is not in the block
}
}
}
}
$p = ($Forward) ? $loc->PosEnd : $loc->PosBeg;
}
// If we are here, then no tag is found, we return the boud of the main element
if ($Forward) {
$p = strpos($Txt, '</office:text');
if ($p===false) return false;
return $p-1;
} else {
$loc = clsTbsXmlLoc::FindStartTag($Txt, 'office:text', $Pos, false);
if ($loc===false) return false;
return $loc->PosEnd + 1;
}
} | php | {
"resource": ""
} |
q248943 | clsOpenTBS.OpenDoc_GetDraw | validation | function OpenDoc_GetDraw($Tag, $Txt, $Pos, $Forward, $LevelStop) {
return $this->XML_BlockAlias_Prefix('draw:', $Txt, $Pos, $Forward, $LevelStop);
} | php | {
"resource": ""
} |
q248944 | clsOpenTBS.OpenDoc_ChartInit | validation | function OpenDoc_ChartInit() {
$this->OpenDocCharts = array();
$idx = $this->Ext_GetMainIdx();
$Txt = $this->TbsStoreGet($idx, 'OpenDoc_ChartInit');
$p = 0;
while($drEl = clsTbsXmlLoc::FindElement($Txt, 'draw:frame', $p)) {
$src = $drEl->GetInnerSrc();
$objEl = clsTbsXmlLoc::FindStartTag($src, 'draw:object', 0);
if ($objEl) { // Picture have <draw:frame> without <draw:object>
$href = $objEl->GetAttLazy('xlink:href'); // example "./Object 1"
if ($href) {
$imgEl = clsTbsXmlLoc::FindElement($src, 'draw:image', 0);
$img_href = ($imgEl) ? $imgEl->GetAttLazy('xlink:href') : false; // "./ObjectReplacements/Object 1"
$img_src = ($imgEl) ? $imgEl->GetSrc('xlink:href') : false;
$titEl = clsTbsXmlLoc::FindElement($src, 'svg:title', 0);
$title = ($titEl) ? $titEl->GetInnerSrc() : '';
if (substr($href,0,2)=='./') $href = substr($href, 2);
if ( is_string($img_href) && (substr($img_href,0,2)=='./') ) $img_href = substr($img_href, 2);
$this->OpenDocCharts[] = array('href'=>$href, 'title'=>$title, 'img_href'=>$img_href, 'img_src'=>$img_src, 'to_clear'=> ($img_href!==false) );
}
}
$p = $drEl->PosEnd;
}
} | php | {
"resource": ""
} |
q248945 | clsOpenTBS.OpenDoc_MsExcelCompatibility | validation | function OpenDoc_MsExcelCompatibility(&$Txt) {
$el_tbl = 'table:table';
$el_col = 'table:table-column'; // Column definition
$el_row = 'table:table-row';
$el_cell = 'table:table-cell';
$att_rep_col = 'table:number-columns-repeated';
$att_rep_row = 'table:number-rows-repeated';
$loop = array($att_rep_col, $att_rep_row);
// Loop for deleting useless repeated columns
foreach ($loop as $att_rep) {
$p = 0;
while ( $xml = clsTbsXmlLoc::FindElementHavingAtt($Txt, $att_rep, $p) ) {
$xml->FindName();
$p = $xml->PosEnd;
// Next tag (opening or closing)
$next = clsTbsXmlLoc::FindStartTagByPrefix($Txt, '', $p);
$next_name = $next->Name;
if ($next_name == '') {
$next_name = $next->GetSrc();
$next_name = substr($next_name, 1, strlen($next_name) -2);
};
$z_src = $next->GetSrc();
//echo " * name=" . $xml->Name . ", suiv_name=$next_name, suiv_src=$z_src\n";
$delete = false;
if ( ($xml->Name == $el_col) && ($xml->SelfClosing) ) {
if ( ($next_name == $el_row) || ($next_name == '/' . $el_tbl) ) {
$delete = true;
}
} elseif ( ($xml->Name == $el_cell) && ($xml->SelfClosing) ) {
if ( $next_name == '/' . $el_row ) {
$delete = true;
}
} elseif ($xml->Name == $el_row) {
if ( $next_name == '/' . $el_tbl ) {
$inner_src = '' . $xml->GetInnerSrc();
if (strpos($inner_src, '<') === false) {
$delete = true;
}
}
}
if ($delete) {
//echo " * SUPPRIME " . $xml->Name . " : " . $xml->GetSrc() . "\n";
$p = $xml->PosBeg;
$xml->Delete();
}
}
}
} | php | {
"resource": ""
} |
q248946 | clsTbsXmlLoc._GetAttValPos | validation | function _GetAttValPos($Att) {
if ($this->pST_Src===false) $this->pST_Src = substr($this->Txt, $this->PosBeg, $this->pST_PosEnd - $this->PosBeg + 1 );
$a = ' '.$Att.'="';
$p0 = strpos($this->pST_Src, $a);
if ($p0!==false) {
$p1 = $p0 + strlen($a);
$p2 = strpos($this->pST_Src, '"', $p1);
if ($p2!==false) return array($p1, $p2-$p1, $p0, $p2-$p0+1);
}
return false;
} | php | {
"resource": ""
} |
q248947 | clsTbsXmlLoc._ApplyDiffFromStart | validation | function _ApplyDiffFromStart($Diff) {
$this->pST_PosEnd += $Diff;
$this->pST_Src = false;
if ($this->pET_PosBeg!==false) $this->pET_PosBeg += $Diff;
$this->PosEnd += $Diff;
} | php | {
"resource": ""
} |
q248948 | clsTbsXmlLoc._ApplyDiffToAll | validation | function _ApplyDiffToAll($Diff) {
$this->PosBeg += $Diff;
$this->PosEnd += $Diff;
$this->pST_PosEnd += $Diff;
if ($this->pET_PosBeg!==false) $this->pET_PosBeg += $Diff;
} | php | {
"resource": ""
} |
q248949 | clsTbsXmlLoc.ReplaceSrc | validation | function ReplaceSrc($new) {
$len = $this->GetLen(); // avoid PHP error : Strict Standards: Only variables should be passed by reference
$this->Txt = substr_replace($this->Txt, $new, $this->PosBeg, $len);
$diff = strlen($new) - $len;
$this->PosEnd += $diff;
$this->pST_Src = false;
if ($new==='') {
$this->pST_PosBeg = false;
$this->pST_PosEnd = false;
$this->pET_PosBeg = false;
} else {
$this->pST_PosEnd += $diff; // CAUTION: may be wrong if attributes has changed
if ($this->pET_PosBeg!==false) $this->pET_PosBeg += $diff; // CAUTION: right only if the tag name is the same
}
} | php | {
"resource": ""
} |
q248950 | clsTbsXmlLoc.GetInnerSrc | validation | function GetInnerSrc() {
return ($this->pET_PosBeg===false) ? false : substr($this->Txt, $this->pST_PosEnd + 1, $this->pET_PosBeg - $this->pST_PosEnd - 1 );
} | php | {
"resource": ""
} |
q248951 | clsTbsXmlLoc.UpdateParent | validation | function UpdateParent($Cascading=false) {
if ($this->Parent) {
$this->Parent->ReplaceSrc($this->Txt);
if ($Cascading) $this->Parent->UpdateParent($Cascading);
}
} | php | {
"resource": ""
} |
q248952 | clsTbsXmlLoc.Delete | validation | function Delete($Contents=true) {
$this->FindEndTag();
if ($Contents || $this->SelfClosing) {
$this->ReplaceSrc('');
} else {
$inner = $this->GetInnerSrc();
$this->ReplaceSrc($inner);
}
} | php | {
"resource": ""
} |
q248953 | clsTbsXmlLoc.FindName | validation | function FindName() {
if ($this->Name==='') {
$p = $this->PosBeg;
do {
$p++;
$z = $this->Txt[$p];
} while ( ($z!==' ') && ($z!=="\r") && ($z!=="\n") && ($z!=='>') && ($z!=='/') );
$this->Name = substr($this->Txt, $this->PosBeg + 1, $p - $this->PosBeg - 1);
}
return $this->Name;
} | php | {
"resource": ""
} |
q248954 | clsTbsXmlLoc.FindEndTag | validation | function FindEndTag($Encaps=false) {
if (is_null($this->SelfClosing)) {
$pe = $this->PosEnd;
$SelfClosing = (substr($this->Txt, $pe-1, 1)=='/');
if (!$SelfClosing) {
if ($Encaps) {
$loc = clsTinyButStrong::f_Xml_FindTag($this->Txt , $this->FindName(), null, $pe, true, -1, false, false);
if ($loc===false) return false;
$this->pET_PosBeg = $loc->PosBeg;
$this->PosEnd = $loc->PosEnd;
} else {
$pe = clsTinyButStrong::f_Xml_FindTagStart($this->Txt, $this->FindName(), false, $pe, true , true);
if ($pe===false) return false;
$this->pET_PosBeg = $pe;
$pe = strpos($this->Txt, '>', $pe);
if ($pe===false) return false;
$this->PosEnd = $pe;
}
}
$this->SelfClosing = $SelfClosing;
}
return true;
} | php | {
"resource": ""
} |
q248955 | clsTbsXmlLoc.switchToRelative | validation | function switchToRelative() {
$this->FindEndTag();
// Save info
$this->rel_Txt = &$this->Txt;
$this->rel_PosBeg = $this->PosBeg;
$this->rel_Len = $this->GetLen();
// Change the univers
$src = $this->GetSrc();
$this->Txt = &$src;
// Change positions
$this->_ApplyDiffToAll(-$this->PosBeg);
} | php | {
"resource": ""
} |
q248956 | clsTbsXmlLoc.FindStartTagByPrefix | validation | static function FindStartTagByPrefix(&$Txt, $TagPrefix, $PosBeg, $Forward=true) {
$x = '<'.$TagPrefix;
$xl = strlen($x);
if ($Forward) {
$PosBeg = strpos($Txt, $x, $PosBeg);
} else {
$PosBeg = strrpos(substr($Txt, 0, $PosBeg+2), $x);
}
if ($PosBeg===false) return false;
// Read the actual tag name
$Tag = $TagPrefix;
$p = $PosBeg + $xl;
do {
$z = substr($Txt,$p,1);
if ( ($z!==' ') && ($z!=="\r") && ($z!=="\n") && ($z!=='>') && ($z!=='/') ) {
$Tag .= $z;
$p++;
} else {
$p = false;
}
} while ($p!==false);
return new clsTbsXmlLoc($Txt, $Tag, $PosBeg);
} | php | {
"resource": ""
} |
q248957 | clsTbsXmlLoc.FindElement | validation | static function FindElement(&$TxtOrObj, $Tag, $PosBeg, $Forward=true) {
$XmlLoc = clsTbsXmlLoc::FindStartTag($TxtOrObj, $Tag, $PosBeg, $Forward);
if ($XmlLoc===false) return false;
$XmlLoc->FindEndTag();
return $XmlLoc;
} | php | {
"resource": ""
} |
q248958 | clsTbsZip.FileGetState | validation | function FileGetState($NameOrIdx) {
$idx = $this->FileGetIdx($NameOrIdx);
if ($idx===false) {
$idx = $this->FileGetIdxAdd($NameOrIdx);
if ($idx===false) {
return false;
} else {
return 'a';
}
} elseif (isset($this->ReplInfo[$idx])) {
if ($this->ReplInfo[$idx]===false) {
return 'd';
} else {
return 'm';
}
} else {
return 'u';
}
} | php | {
"resource": ""
} |
q248959 | clsTinyButStrong.meth_Conv_Prepare | validation | function meth_Conv_Prepare(&$Loc, $StrConv) {
$x = strtolower($StrConv);
$x = '+'.str_replace(' ','',$x).'+';
if (strpos($x,'+esc+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvStr = false; $Loc->ConvEsc = true; }
if (strpos($x,'+wsp+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvWS = true; }
if (strpos($x,'+js+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvStr = false; $Loc->ConvJS = true; }
if (strpos($x,'+url+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvStr = false; $Loc->ConvUrl = true; }
if (strpos($x,'+utf8+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvStr = false; $Loc->ConvUtf8 = true; }
if (strpos($x,'+no+')!==false) $Loc->ConvStr = false;
if (strpos($x,'+yes+')!==false) $Loc->ConvStr = true;
if (strpos($x,'+nobr+')!==false) {$Loc->ConvStr = true; $Loc->ConvBr = false; }
} | php | {
"resource": ""
} |
q248960 | clsTinyButStrong.meth_Conv_Str | validation | function meth_Conv_Str(&$Txt,$ConvBr=true) {
if ($this->Charset==='') { // Html by default
$Txt = htmlspecialchars($Txt);
if ($ConvBr) $Txt = nl2br($Txt);
} elseif ($this->_CharsetFct) {
$Txt = call_user_func($this->Charset,$Txt,$ConvBr);
} else {
$Txt = htmlspecialchars($Txt,ENT_COMPAT,$this->Charset);
if ($ConvBr) $Txt = nl2br($Txt);
}
} | php | {
"resource": ""
} |
q248961 | clsTinyButStrong.f_Misc_UpdateArray | validation | static function f_Misc_UpdateArray(&$array, $numerical, $v, $d) {
if (!is_array($v)) {
if (is_null($v)) {
$array = array();
return;
} else {
$v = array($v=>$d);
}
}
foreach ($v as $p=>$a) {
if ($numerical===true) { // numerical keys
if (is_string($p)) {
// syntax: item => true/false
$i = array_search($p, $array, true);
if ($i===false) {
if (!is_null($a)) $array[] = $p;
} else {
if (is_null($a)) array_splice($array, $i, 1);
}
} else {
// syntax: i => item
$i = array_search($a, $array, true);
if ($i==false) $array[] = $a;
}
} else { // string keys
if (is_null($a)) {
unset($array[$p]);
} elseif ($numerical==='frm') {
self::f_Misc_FormatSave($a, $p);
} else {
$array[$p] = $a;
}
}
}
} | php | {
"resource": ""
} |
q248962 | MahasiswaController.actionIndex | validation | public function actionIndex()
{
$searchModel = new MahasiswaSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$field = [
'fileImport' => 'File Import',
];
$modelImport = DynamicModel::validateData($field, [
[['fileImport'], 'required'],
[['fileImport'], 'file', 'extensions'=>'xls,xlsx','maxSize'=>1024*1024],
]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'modelImport' => $modelImport,
]);
} | php | {
"resource": ""
} |
q248963 | clsTinyButStrong.meth_Misc_Alert | validation | function meth_Misc_Alert($Src,$Msg,$NoErrMsg=false,$SrcType=false) {
$this->ErrCount++;
if ($this->NoErr || (php_sapi_name==='cli') ) {
$t = array('','','','','');
} else {
$t = array('<br /><b>','</b>','<em>','</em>','<br />');
$Msg = htmlentities($Msg);
}
if (!is_string($Src)) {
if ($SrcType===false) $SrcType='in field';
if (isset($Src->PrmLst['tbstype'])) {
$Msg = 'Column \''.$Src->SubName.'\' is expected but missing in the current record.';
$Src = 'Parameter \''.$Src->PrmLst['tbstype'].'='.$Src->SubName.'\'';
$NoErrMsg = false;
} else {
$Src = $SrcType.' '.$this->_ChrOpen.$Src->FullName.'...'.$this->_ChrClose;
}
}
$x = $t[0].'TinyButStrong Error'.$t[1].' '.$Src.': '.$Msg;
if ($NoErrMsg) $x = $x.' '.$t[2].'This message can be cancelled using parameter \'noerr\'.'.$t[3];
$x = $x.$t[4]."\n";
if ($this->NoErr) {
$this->ErrMsg .= $x;
} else {
if (php_sapi_name!=='cli') {
$x = str_replace($this->_ChrOpen,$this->_ChrProtect,$x);
}
echo $x;
}
return false;
} | php | {
"resource": ""
} |
q248964 | Helper.objectToArray | validation | public function objectToArray($object, $array = [])
{
$reflectionClass = new \ReflectionClass(get_class($object));
foreach ($reflectionClass->getProperties() as $property) {
$property->setAccessible(true);
$name = trim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $property->getName())), '_');
if (empty($property->getValue($object))) {
continue;
} else if (is_object($property->getValue($object))) {
$array[$name] = $this->objectToArray($property->getValue($object));
} else if (is_array($property->getValue($object))) {
foreach ($property->getValue($object) as $key => $value) {
if (is_object($value)) {
$array[$name][] = $this->objectToArray($value);
}
}
} else {
$array[$name] = $property->getValue($object);
}
$property->setAccessible(false);
}
return $array;
} | php | {
"resource": ""
} |
q248965 | Message.setQuickReplies | validation | public function setQuickReplies($quickReplie)
{
$model = new QuickReplie();
$type = !empty($quickReplie['type']) ? $quickReplie['type'] : 'text';
$model->setContentType($type);
if (!empty($quickReplie['title'])) {
$model->setPayload($quickReplie['payload']);
}
if (!empty($quickReplie['title'])) {
$model->setTitle($quickReplie['title']);
}
if (!empty($quickReplie['image'])) {
$model->setImageUrl($quickReplie['image']);
}
$this->quickReplies[] = $model;
} | php | {
"resource": ""
} |
q248966 | Message.url | validation | public function url($text, $title, $url)
{
$payload = [
'template_type' => 'button',
'text' => $text,
'buttons' => [
[
'title' => $title,
'url' => $url
]
],
];
$this->setAttachment('template', $payload);
return $this;
} | php | {
"resource": ""
} |
q248967 | Message.postback | validation | public function postback($text, $title, $postback)
{
$payload = [
'template_type' => 'button',
'text' => $text,
'buttons' => [
[
'type' => 'postback',
'title' => $title,
'payload' => $postback
]
],
];
$this->setAttachment('template', $payload);
return $this;
} | php | {
"resource": ""
} |
q248968 | Message.login | validation | public function login($text, $url)
{
$payload = [
'template_type' => 'button',
'text' => $text,
'buttons' => [
[
'type' => 'account_link',
'url' => $url
]
],
];
$this->setAttachment('template', $payload);
return $this;
} | php | {
"resource": ""
} |
q248969 | Message.quickReplies | validation | public function quickReplies($text, $quickReplies)
{
$this->setText($text);
foreach ($quickReplies as $quickReplie) {
$this->setQuickReplies($quickReplie);
}
return $this;
} | php | {
"resource": ""
} |
q248970 | Message.quickReplie | validation | public function quickReplie($text, $title, $postback, $image = null)
{
$this->setText($text);
$payload = [
'title' => $title,
'payload' => $postback,
];
if (!empty($image)) {
$payload['image'] = $image;
}
$this->setQuickReplies($payload);
return $this;
} | php | {
"resource": ""
} |
q248971 | Messenger.api | validation | public function api($url, $body = null, $type = self::TYPE_POST)
{
$body['access_token'] = $this->accessToken;
$this->setBody($body);
$headers = [
'Content-Type: application/json',
];
if ($type == self::TYPE_GET) {
$url .= '?'.http_build_query($body);
}
$curl = curl_init($this->url . $url);
if($type == self::TYPE_POST) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($body));
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response, true);
} | php | {
"resource": ""
} |
q248972 | DateTimeNormalizer.supportsNormalization | validation | public function supportsNormalization($data, $format = null)
{
return is_object($data) && ($data instanceof \DateTime) && (self::FORMAT === $format);
} | php | {
"resource": ""
} |
q248973 | DateTimeNormalizer.denormalize | validation | public function denormalize($data, $class, $format = null, array $context = array())
{
$value = $data;
if (is_array($data)) {
if (!isset($data['@value']) || !isset($data['@type'])) {
throw new RuntimeException(
"Cannot denormalize the data as it isn't a valid JSON-LD typed value: " .
var_export($data, true)
);
}
if (self::XSD_DATETIME_IRI !== $data['@type']) {
throw new RuntimeException(
"Cannot denormalize the data as it isn't a XSD dateTime value: " .
var_export($data, true)
);
}
$value = $data['@value'];
} elseif (!is_string($data)) {
throw new RuntimeException(
"Cannot denormalize the data into a DateTime object: " .
var_export($data, true)
);
}
try {
$date = new \DateTime($value);
return $date;
} catch(Exception $e) {
throw new RuntimeException(
"Cannot denormalize the data as the value is invalid: " . var_export($data, true),
0,
$e
);
}
} | php | {
"resource": ""
} |
q248974 | SerializerListener.onKernelView | validation | public function onKernelView(GetResponseForControllerResultEvent $event)
{
$request = $event->getRequest();
$result = $event->getControllerResult();
if (!$request->attributes->get('__hydra_serialize')) {
return;
}
if (is_array($result) || ($result instanceof \ArrayAccess) || ($result instanceof \Traversable)) {
$result = new Collection($request->getUri(), $result);
} elseif (null === $result) {
$event->setResponse(new JsonLdResponse('', 200));
return;
} elseif (!is_object($result)) {
throw new \Exception("A Hydra controller must return either an array or an object, got a(n) " . gettype($result));
}
$serialized = $this->serializer->serialize($result, 'jsonld');
$event->setResponse(new JsonLdResponse($serialized));
} | php | {
"resource": ""
} |
q248975 | SerializerListener.isHydraOperation | validation | private function isHydraOperation(\ReflectionMethod $method)
{
$annotation = $this->annotationReader->getMethodAnnotation(
$method,
'ML\HydraBundle\Mapping\Operation'
);
return null !== $annotation;
} | php | {
"resource": ""
} |
q248976 | AnnotationDriver.documentRouteAndOperations | validation | private function documentRouteAndOperations($metadata, Reflector $element)
{
if ((null !== ($annotation = $this->getAnnotation($element, 'ML\HydraBundle\Mapping\Id'))) ||
(null !== ($annotation = $this->getAnnotation($element, 'ML\HydraBundle\Mapping\Route')))) {
// TODO Check that the IRI template can be filled!?
$metadata->setRoute($this->getRouteMetadata($annotation->route));
}
$annotation = $this->getAnnotation($element, 'ML\HydraBundle\Mapping\Operations');
if (null !== $annotation) {
$operations = array_unique($annotation->operations);
$operationsMetadata = array_map(array($this, 'getRouteMetadata'), $operations);
$metadata->setOperations($operationsMetadata);
}
if (null !== ($route = $metadata->getRoute())) {
// Add the route to the supported operations
$metadata->addOperation($this->getRouteMetadata($route->getName()));
} elseif (null !== $annotation) {
// ... or use an operation as route if none is set
// FIXXME: Do this only for GET operations!
$metadata->setRoute($this->getRouteMetadata(reset($annotation->operations)));
}
if (($metadata instanceof PropertyDefinition) && (count($operations = $metadata->getOperations()) > 0)) {
foreach ($operations as $operation) {
if (('GET' === $operation->getMethod()) && (null !== $operation->getReturns())) {
$metadata->setType($operation->getReturns());
return;
}
}
$metadata->setType('ML\HydraBundle\Entity\Resource');
}
} | php | {
"resource": ""
} |
q248977 | AnnotationDriver.documentProperties | validation | private function documentProperties(ClassMetadata $metadata, ReflectionClass $class)
{
/*
$interfaces = $class->getInterfaces();
$linkRelationMethods = array();
foreach ($interfaces as $interface) {
if (null !== $this->getAnnotation($interface, $linkRelationAnnot)) {
if (false === isset($documentation['rels'][$interface->name])) {
$documentation['rels'][$interface->name] = array();
foreach ($interface->getMethods() as $method) {
if ($method->isPublic()) {
$documentation['rels'][$interface->name][$method->name] = $interface->name;
}
}
}
$linkRelationMethods += $documentation['rels'][$interface->name];
}
}
*/
$properties = array();
$elements = array_merge($class->getProperties(), $class->getMethods());
foreach ($elements as $element) {
$annotation = $this->getAnnotation($element, 'ML\HydraBundle\Mapping\Expose');
if (null === $annotation) {
continue;
}
// $exposeAs = $element->name;
// if ($annotation->as) {
// $exposeAs = $annotation->as;
// if ($annotation->getIri()) {
// $property['iri'] = $annotation->getIri();
// } else {
// $property['iri'] = $exposeClassAs . '/' . $exposeAs;
// }
// } else {
// $exposeAs = $this->propertirize($exposeAs);
// if ($annotation->getIri()) {
// $property['iri'] = $annotation->getIri();
// } else {
// $property['iri'] = $this->camelize($exposeAs);
// $property['iri'][0] = strtolower($property['iri'][0]);
// $property['iri'] = $exposeClassAs . '/' . $property['iri'];
// }
// }
$property = new PropertyDefinition($class->name, $element->name);
$property->setExposeAs($annotation->as);
$property->setIri($annotation->getIri());
if (null !== $annotation->required) {
$property->setRequired($annotation->required);
}
if (null !== $annotation->readonly) {
$property->setReadOnly($annotation->readonly);
}
if (null !== $annotation->writeonly) {
$property->setWriteOnly($annotation->writeonly);
}
$tmp = $this->getDocBlockText($element);
$property->setTitle($tmp['title']);
$property->setDescription($tmp['description']);
$tmp = $this->getType($element);
$property->setType($tmp['type']);
$this->documentRouteAndOperations($property, $element);
if (null !== ($annotation = $this->getAnnotation($element, 'ML\HydraBundle\Mapping\Collection'))) {
// TODO Check for conflicting routes!?
// TODO Check that the IRI template can be filled!?
$property->setRoute($this->getRouteMetadata($annotation->route));
if (false === $property->supportsOperation($annotation->route)) {
$property->addOperation($this->getRouteMetadata($annotation->route));
}
$property->setType('ML\HydraBundle\Entity\Collection');
$property->setReadOnly(true);
}
/*
if ($element instanceof ReflectionMethod) {
if (array_key_exists($element->name, $linkRelationMethods)) {
$property['original_type'] .= ' --- ' . $linkRelationMethods[$element->name] . '::' . $element->name;
}
}
*/
// TODO Validate definition, this here isn't the right place to do so, create a metadata factory
$properties[] = $property;
}
// $documentation['class2type'][$class->name] = $exposeClassAs;
// $documentation['types'][$exposeClassAs] = $result;
$metadata->setProperties($properties);
} | php | {
"resource": ""
} |
q248978 | AnnotationDriver.getAnnotation | validation | private function getAnnotation(Reflector $element, $annotation)
{
if ($element instanceof ReflectionClass) {
return $this->reader->getClassAnnotation($element, $annotation);
} elseif ($element instanceof ReflectionMethod) {
return $this->reader->getMethodAnnotation($element, $annotation);
} elseif ($element instanceof ReflectionProperty) {
return $this->reader->getPropertyAnnotation($element, $annotation);
}
return null;
} | php | {
"resource": ""
} |
q248979 | HydraController.serialize | validation | public function serialize($entity)
{
if (!$this->container->has('hydra.serializer')) {
throw new \LogicException('The HydraBundle is not registered in your application.');
}
return $this->container->get('hydra.serializer')->serialize($entity, self::FORMAT);
} | php | {
"resource": ""
} |
q248980 | HydraController.deserialize | validation | public function deserialize($data, $entity)
{
if (!$this->container->has('hydra.serializer')) {
throw new \LogicException('The HydraBundle is not registered in your application.');
}
$serializer = $this->container->get('hydra.serializer');
if (is_object($entity)) {
return $serializer->deserializeIntoEntity($data, $entity);
}
return $serializer->deserialize($data, $entity, self::FORMAT);
} | php | {
"resource": ""
} |
q248981 | HydraController.validate | validation | public function validate($entity)
{
if (!$this->container->has('validator')) {
throw new \LogicException('The validator service is not available.');
}
$errors = $this->container->get('validator')->validate($entity);
if (count($errors) === 0) {
return false;
}
// TODO Use Hydra Error instead
return new JsonLdResponse('{ "error": "Validation error" }', 400);
} | php | {
"resource": ""
} |
q248982 | PropertyDefinition.addOperation | validation | public function addOperation(OperationDefinition $operation)
{
if (false === $this->supportsOperation($operation->getName())) {
$this->operations[] = $operation;
}
return $this;
} | php | {
"resource": ""
} |
q248983 | PropertyDefinition.supportsOperation | validation | public function supportsOperation($operationName)
{
foreach ($this->operations as $operation) {
if ($operation->getName() === $operationName) {
return true;
}
}
return false;
} | php | {
"resource": ""
} |
q248984 | PropertyDefinition.setValue | validation | public function setValue($entity, $value)
{
if (false === ($entity instanceof $this->class)) {
// FIXXME Improve this message
throw new \Exception(
"Can't set the entity's {$this->name} property as the entity is not an instance of {$this->class}."
);
}
if (!is_array($value) && !($value instanceof \Traversable)) {
if ((null !== $this->adderRemover) && (null !== $this->getter)) {
// Use iterator_to_array() instead of clone in order to prevent side effects
// see https://github.com/symfony/symfony/issues/4670
$itemsToAdd = is_object($value) ? iterator_to_array($value) : $value;
$itemToRemove = array();
$previousValue = $this->getValue($entity);
if (is_array($previousValue) || $previousValue instanceof \Traversable) {
foreach ($previousValue as $previousItem) {
foreach ($value as $key => $item) {
if ($item === $previousItem) {
// Item found, don't add
unset($itemsToAdd[$key]);
// Next $previousItem
continue 2;
}
}
// Item not found, add to remove list
$itemToRemove[] = $previousItem;
}
}
foreach ($itemToRemove as $item) {
call_user_func(array($entity, 'remove' . $this->adderRemover), $item);
}
foreach ($itemsToAdd as $item) {
call_user_func(array($entity, 'add' . $this->adderRemover), $item);
}
return;
}
}
if (null === $this->setter) {
// FIXXME Improve this message
throw new \Exception(
"Can't set the entity's {$this->name} property as no setter has been found."
);
}
if (self::GETTER_SETTER_METHOD === $this->setterType) {
return $entity->{$this->setter}($value);
} else {
return $entity->{$this->setter} = $value;
}
} | php | {
"resource": ""
} |
q248985 | PropertyDefinition.getValue | validation | public function getValue($entity)
{
if (null === $this->getter) {
// FIXXME Improve this message
throw new \Exception(
"Can't get the entity's {$this->name} property as no getter has been found."
);
} elseif (false === ($entity instanceof $this->class)) {
// FIXXME Improve this message
throw new \Exception(
"Can't get the entity's {$this->name} property as the entity is not an instance of {$this->class}."
);
}
if (self::GETTER_SETTER_METHOD === $this->getterType) {
return $entity->{$this->getter}();
} else {
return $entity->{$this->getter};
}
} | php | {
"resource": ""
} |
q248986 | PropertyDefinition.findGetter | validation | private function findGetter()
{
$reflClass = new \ReflectionClass($this->class);
$camelProp = $this->camelize($this->name);
// Try to find a getter
$getter = 'get'.$camelProp;
$isser = 'is'.$camelProp;
$hasser = 'has'.$camelProp;
$classHasProperty = $reflClass->hasProperty($this->name);
if ($reflClass->hasMethod($this->name) && $reflClass->getMethod($this->name)->isPublic()) {
$this->getter = $this->name;
$this->getterType = self::GETTER_SETTER_METHOD;
} elseif ($reflClass->hasMethod($getter) && $reflClass->getMethod($getter)->isPublic()) {
$this->getter = $getter;
$this->getterType = self::GETTER_SETTER_METHOD;
} elseif ($reflClass->hasMethod($isser) && $reflClass->getMethod($isser)->isPublic()) {
$this->getter = $isser;
$this->getterType = self::GETTER_SETTER_METHOD;
} elseif ($reflClass->hasMethod($hasser) && $reflClass->getMethod($hasser)->isPublic()) {
$this->getter = $hasser;
$this->getterType = self::GETTER_SETTER_METHOD;
} elseif (($reflClass->hasMethod('__get') && $reflClass->getMethod('__get')->isPublic()) ||
($classHasProperty && $reflClass->getProperty($this->name)->isPublic())) {
$this->getter = $this->name;
$this->getterType = self::GETTER_SETTER_PROPERTY;
// } elseif ($this->magicCall && $reflClass->hasMethod('__call') && $reflClass->getMethod('__call')->isPublic()) {
// // we call the getter and hope the __call do the job
// $result[self::VALUE] = $object->$getter();
}
} | php | {
"resource": ""
} |
q248987 | PropertyDefinition.findSetter | validation | private function findSetter()
{
$reflClass = new \ReflectionClass($this->class);
$setter = 'set' . $this->camelize($this->name);
$classHasProperty = $reflClass->hasProperty($this->name);
if ($reflClass->hasMethod($setter) && $reflClass->getMethod($setter)->isPublic()) {
$this->setter = $setter;
$this->setterType = self::GETTER_SETTER_METHOD;
} elseif ((0 === strpos($this->name, 'set')) && $reflClass->hasMethod($this->name) && $reflClass->getMethod($this->name)->isPublic()) {
$this->setter = $this->name;
$this->setterType = self::GETTER_SETTER_METHOD;
} elseif (($reflClass->hasMethod('__set') && $reflClass->getMethod('__set')->isPublic()) ||
($classHasProperty && $reflClass->getProperty($this->name)->isPublic())) {
$this->setter = $this->name;
$this->setterType = self::GETTER_SETTER_PROPERTY;
// } elseif ($this->magicCall && $reflClass->hasMethod('__call') && $reflClass->getMethod('__call')->isPublic()) {
// // we call the getter and hope the __call do the job
// $object->$setter($value);
}
} | php | {
"resource": ""
} |
q248988 | PropertyDefinition.findAdderAndRemover | validation | private function findAdderAndRemover()
{
$reflClass = new \ReflectionClass($this->class);
$singulars = (array) StringUtil::singularify($this->camelize($this->name));
foreach ($singulars as $singular) {
$addMethod = 'add'.$singular;
$removeMethod = 'remove'.$singular;
$addMethodFound = $this->isAccessible($reflClass, $addMethod, 1);
$removeMethodFound = $this->isAccessible($reflClass, $removeMethod, 1);
if ($addMethodFound && $removeMethodFound) {
$this->adderRemover = $singular;
return;
}
}
} | php | {
"resource": ""
} |
q248989 | PropertyDefinition.isAccessible | validation | private function isAccessible(\ReflectionClass $class, $methodName, $parameters)
{
if ($class->hasMethod($methodName)) {
$method = $class->getMethod($methodName);
if ($method->isPublic() && $method->getNumberOfRequiredParameters() === $parameters) {
return true;
}
}
return false;
} | php | {
"resource": ""
} |
q248990 | ClassMetadataFactory.getAllMetadata | validation | public function getAllMetadata()
{
// FIXXME Should this be implemented here or in the driver (chain)?
$metadata = array();
foreach ($this->driver->getAllClassNames() as $className) {
$metadata[] = $this->getMetadataFor($className);
}
$this->validate($metadata);
return $metadata;
} | php | {
"resource": ""
} |
q248991 | ClassMetadataFactory.getMetadataFor | validation | public function getMetadataFor($className)
{
if (isset($this->loadedMetadata[$className])) {
return $this->loadedMetadata[$className];
}
$realClassName = ClassUtils::getRealClass($className);
if (isset($this->loadedMetadata[$realClassName])) {
// We do not have the alias name in the map, include it
$this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
return $this->loadedMetadata[$realClassName];
}
if ($this->cacheDriver) {
if (($cached = $this->cacheDriver->fetch($realClassName . $this->cacheSalt)) !== false) {
$this->loadedMetadata[$realClassName] = $cached;
} else {
$this->cacheDriver->save(
$realClassName . $this->cacheSalt, $this->loadMetadata($realClassName), null
);
}
} else {
$this->loadMetadata($realClassName);
}
if ($className != $realClassName) {
// We do not have the alias name in the map, include it
$this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
}
return $this->loadedMetadata[$className];
} | php | {
"resource": ""
} |
q248992 | ClassMetadataFactory.loadMetadata | validation | protected function loadMetadata($className)
{
if (false === isset($this->loadedMetadata[$className])) {
if (null === ($class = $this->driver->loadMetadataForClass($className))) {
// FIXXME Improve this
throw new \Exception("Can't load metadata for $className");
}
$this->completeMetadata($class);
$this->loadedMetadata[$className] = $class;
}
return $this->loadedMetadata[$className];
} | php | {
"resource": ""
} |
q248993 | ClassMetadataFactory.completeMetadata | validation | protected function completeMetadata(ClassMetadata $class)
{
$className = $class->getName();
if (null === $class->getIri()) {
$class->setIri($this->namingStrategy->classIriFragment($className));
}
if (null === $class->getExposeAs()) {
$class->setExposeAs($this->namingStrategy->classShortName($className));
}
// If no title has been set for this class, use it's short name
if (null === $class->getTitle()) {
$class->setTitle($this->namingStrategy->classShortName($className));
}
foreach ($class->getProperties() as $property) {
$propertyName = $property->getName();
if (null === $property->getIri()) {
$property->setIri(
$this->namingStrategy->propertyIriFragment($className, $propertyName)
);
}
if (null === $property->getExposeAs()) {
$property->setExposeAs(
$this->namingStrategy->propertyShortName($className, $propertyName)
);
}
// If no title has been set for this property, use it's short name
if (null === $property->getTitle()) {
$property->setTitle(
$this->namingStrategy->propertyShortName($className, $propertyName)
);
}
}
} | php | {
"resource": ""
} |
q248994 | Serializer.serialize | validation | public function serialize($data, $format, array $context = array())
{
if ('jsonld' !== $format) {
throw new UnexpectedValueException('Serialization for the format ' . $format . ' is not supported');
}
if (false === is_object($data)) {
throw new \Exception('Only objects can be serialized');
}
return JsonLD::toString($this->doSerialize($data, true), true);
} | php | {
"resource": ""
} |
q248995 | Serializer.deserialize | validation | public function deserialize($data, $type, $format, array $context = array())
{
if ('jsonld' !== $format) {
throw new UnexpectedValueException('Deserialization for the format ' . $format . ' is not supported');
}
$reflectionClass = new \ReflectionClass($type);
if (null !== ($constructor = $reflectionClass->getConstructor())) {
if (0 !== $constructor->getNumberOfRequiredParameters()) {
throw new RuntimeException(
'Cannot create an instance of '. $type .
' from serialized data because its constructor has required parameters.'
);
}
}
return $this->doDeserialize($data, new $type);
} | php | {
"resource": ""
} |
q248996 | Serializer.doDeserialize | validation | private function doDeserialize($data, $entity)
{
$metadata = $this->hydraApi->getMetadataFor(get_class($entity));
if (null === $metadata) {
// TODO Improve this error message
throw new \Exception(sprintf('"%s" cannot be serialized as it is not documented.', get_class($data)));
}
$vocabPrefix = $this->router->generate('hydra_vocab', array(), true) . '#';
$typeIri = ($metadata->isExternalReference())
? $metadata->getIri()
: $vocabPrefix . $metadata->getIri();
$graph = JsonLD::getDocument($data)->getGraph();
$node = $graph->getNodesByType($typeIri);
if (1 !== count($node)) {
throw new RuntimeException(
'The passed data contains '. count($node) . ' nodes of the type ' .
$typeIri . '; expected 1.'
);
}
$node = reset($node);
foreach ($metadata->getProperties() as $property) {
if ($property->isReadOnly()) {
continue;
}
// TODO Parse route!
if (null !== ($route = $property->getRoute())) {
continue; // FIXXE Handle properties whose value are URLs
}
// TODO Recurse!?
$propertyIri = ($property->isExternalReference())
? $property->getIri()
: $vocabPrefix . $property->getIri();
$value = $node->getProperty($propertyIri);
if ($value instanceof \ML\JsonLD\Value) {
$value = $value->getValue();
}
if (!is_null($value) && $this->hydraApi->hasNormalizer($property->getType())) {
$normalizer = $this->hydraApi->getNormalizer($property->getType());
$value = $normalizer->denormalize($value, $property->getType());
}
$property->setValue($entity, $value); // TODO Fix IRI construction
// if (is_array($value) || ($value instanceof \ArrayAccess) || ($value instanceof \Travesable)) {
// $result[$property] = array();
// foreach ($value as $val) {
// $result[$property][] = $this->doSerialize($val);
// }
// } else {
// $result[$property] = $value;
// }
}
return $entity;
} | php | {
"resource": ""
} |
q248997 | ClassMetadata.setPropertyValue | validation | public function setPropertyValue($entity, $property, $value)
{
$this->reflFields[$property]->setValue($entity, $value);
} | php | {
"resource": ""
} |
q248998 | JsonLdResponse.processData | validation | public function processData($data = array())
{
// return an empty object instead of an empty array
if (is_array($data) && 0 === count($data)) {
$data = new \stdClass();
}
if (!is_string($data)) {
$options = 0;
if (PHP_VERSION_ID >= 50400)
{
$options |= JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
if (self::$pretty)
{
$options |= JSON_PRETTY_PRINT;
}
$data = json_encode($data, $options);
}
else
{
$data = json_encode($data);
$data = str_replace('\\/', '/', $data); // unescape slahes
// unescape unicode
$data = preg_replace_callback(
'/\\\\u([a-f0-9]{4})/',
function ($match) {
return iconv('UCS-4LE', 'UTF-8', pack('V', hexdec($match[1])));
},
$data);
}
}
return $this->setContent($data);
} | php | {
"resource": ""
} |
q248999 | HydraExtension.loadMappingInformation | validation | protected function loadMappingInformation(array $config, ContainerBuilder $container)
{
// FIXXME Remove $this->drivers if possible
// reset state of drivers map. They are only used by this methods and children.
$this->drivers = array();
if ($config['auto_mapping']) {
// automatically register bundle mappings
foreach (array_keys($container->getParameter('kernel.bundles')) as $bundle) {
if (!isset($config['mappings'][$bundle])) {
$config['mappings'][$bundle] = array(
'mapping' => true,
'is_bundle' => true,
);
}
}
}
$container->setAlias('hydra.naming_strategy', new Alias($config['naming_strategy'], false));
foreach ($config['mappings'] as $mappingName => $mappingConfig) {
if (null !== $mappingConfig && false === $mappingConfig['mapping']) {
continue;
}
$mappingConfig = array_replace(array(
'dir' => false,
'type' => false,
'prefix' => false,
), (array) $mappingConfig);
$mappingConfig['dir'] = $container->getParameterBag()->resolveValue($mappingConfig['dir']);
// a bundle configuration is detected by realizing that the specified dir is not absolute and existing
if (!isset($mappingConfig['is_bundle'])) {
$mappingConfig['is_bundle'] = !is_dir($mappingConfig['dir']);
}
if ($mappingConfig['is_bundle']) {
$bundle = null;
foreach ($container->getParameter('kernel.bundles') as $name => $class) {
if ($mappingName === $name) {
$bundle = new \ReflectionClass($class);
break;
}
}
if (null === $bundle) {
throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled.', $mappingName));
}
$mappingConfig = $this->getMappingDriverBundleConfigDefaults($mappingConfig, $bundle, $container);
if (!$mappingConfig) {
continue;
}
}
$this->validateMappingConfiguration($mappingConfig, $mappingName);
$this->setMappingDriverConfig($mappingConfig, $mappingName);
}
$this->registerMappingDrivers($config, $container);
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.