function parse_array($arrayNode)
{
    $array = array();
    for ($node = $arrayNode->firstChild; $node != null; $node = $node->nextSibling) {
        if ($node->nodeType == XML_ELEMENT_NODE) {
            array_push($array, parseValue($node));
        }
    }
    return $array;
}
Example #2
0
function parsePlist($path)
{
    $document = new DOMDocument();
    $document->load($path);
    $plistNode = $document->documentElement;
    $root = $plistNode->firstChild;
    while ($root->nodeName == "#text") {
        $root = $root->nextSibling;
    }
    return parseValue($root);
}
Example #3
0
function generateFieldOptions($type, $field, $empty, $value = '')
{
    global $TYPES;
    $return = $empty == true ? '<option value=""></option>' : '';
    $options = $TYPES[$type]['fields'][$field]['typeData'][1];
    foreach ($options as $option) {
        $selected = $option == $value ? ' selected' : '';
        //slightly risky, as we could send a field that relies on another field to parse, but I'm going to say that's unlikely
        $item[$field] = $option;
        $parsed = parseValue($type, $item);
        $return .= '<option value="' . $option . '"' . $selected . '>' . $parsed[$field] . '</option>';
    }
    return $return;
}
         continue;
     }
     $rowIndex = $row->getRowIndex();
     $profile = array();
     $phpExcelCellIterator = $row->getCellIterator();
     $phpExcelCellIterator->setIterateOnlyExistingCells(false);
     $index = 0;
     foreach ($phpExcelCellIterator as $cell) {
         if ($cell->getColumn() == 'A') {
             if ($cell->getValue() == '') {
                 continue;
             }
         }
         $cellColumn = $cell->getColumn();
         if ($cellColumn == 'A' || $cellColumn == 'C' || $cellColumn == 'D' || $cellColumn == 'E' || $cellColumn == 'F' || $cellColumn == 'I' || $cellColumn == 'J') {
             $profile[$profileDetails[$index]] = parseValue($cell->getValue());
         } else {
             if ($cellColumn == 'H') {
                 $profile[$profileDetails[$index]] = parseString($cell->getValue());
             } else {
                 $profile[$profileDetails[$index]] = parseNumber($cell->getValue());
             }
         }
         $index++;
     }
     setPost('upload', addProfile($profile));
     // TODO: Detect if there are collision of ID numbers
     if (getPost('upload') == 'success') {
         $addedProfiles++;
     }
 }
Example #5
0
foreach ($columns as $column) {
    $formalName = !isset($TYPES[$_GET['type']]['fields'][$column]) && $column == 'name' ? 'Name' : $TYPES[$_GET['type']]['fields'][$column]['formalName'];
    echo '<th>' . $formalName . '</th>';
}
?>
				</tr>
			</thead>
			<tbody>
				<?php 
$sth = $dbh->prepare('SELECT *
						FROM ' . $TYPES[$_GET['type']]['pluralName'] . '
						WHERE active = 1');
$sth->execute();
while ($row = $sth->fetch()) {
    $id = $row[$TYPES[$_GET['type']]['idName']];
    $item = parseValue($_GET['type'], $row);
    echo '<tr><td class="selectCol"><input type="checkbox" class="selectCheckbox" id="' . $id . '"></td>';
    foreach ($columns as $column) {
        if ($column == 'name' || $column == 'orderID' || $column == 'expenseID') {
            $temp = getLinkedName($_GET['type'], $id);
        } else {
            $temp = $item[$column];
        }
        echo '<td>' . $temp . '</td>';
    }
    echo '</tr>';
}
?>
			</tbody>
		</table>
		<?php 
Example #6
0
function getValueForTemplateField($pageName, $infoboxContents, $fieldInfo)
{
    global $bot, $gImportWikiSubstring;
    if (is_array($fieldInfo)) {
        $fieldName = $fieldInfo[0];
        preg_match('/\\|[ ]*' . $fieldName . '[ ]*=[ ]*(.*)/', $infoboxContents, $matches);
        $fieldValue = $matches[1];
        foreach ($fieldInfo as $specialHandling => $handlingInfo) {
            if ($specialHandling === 0) {
                continue;
            }
            if ($specialHandling == 'forbidden') {
                $forbiddenValues = $handlingInfo;
                $fieldValue = parseValue($fieldValue);
                if (in_array($fieldValue, $forbiddenValues)) {
                    // We need an exception here so that
                    // the calling code knows not to
                    // create a line.
                    throw new Exception('Forbidden value');
                }
            } elseif ($specialHandling == 'lowercase') {
                $fieldValue = parseValue($fieldValue);
                $fieldValue = strtolower($fieldValue);
            } elseif ($specialHandling == 'units' && $fieldValue != '') {
                $fieldValue = parseCompoundValue($fieldValue);
                $searchString = '\\{\\{[Cc]onvert\\|';
                preg_match_all('/' . $searchString . '([^|]*)\\|([^|}]*)/', $fieldValue, $matches2);
                $fieldValue = $matches2[1][0];
                // Get rid of commas in numbers - PHP
                // can't handle them.
                $fieldValue = str_replace(',', '', $fieldValue);
                $fieldValue = parseValue($fieldValue);
                $curUnit = $matches2[2][0];
                // Maybe there's no "{{convert}}" template there
                if ($curUnit == '') {
                    // Get rid of anything in parentheses
                    $fieldValue = preg_replace('/\\(.*\\)/', '', $fieldValue);
                    // Get rid of commas in numbers - PHP can't
                    // handle them.
                    $fieldValue = str_replace(',', '', $fieldValue);
                    $fieldValue = trim($fieldValue);
                    list($fieldValue, $curUnit) = explode(' ', $fieldValue, 2);
                }
                if ($curUnit != '') {
                    $newUnit = $handlingInfo;
                    $fieldValue = convertToUnits($fieldValue, $curUnit, $newUnit);
                }
            } elseif ($specialHandling == 'birth date' && $fieldValue != '') {
                // Birth date
                preg_match('/[Bb]irth.date( and age)?(\\|mf=yes)?(\\|df=y)?\\|(\\d*)\\|(\\d*)\\|(\\d*)/', $fieldValue, $matches);
                if ($matches[4] != '') {
                    $date = $matches[4] . '-' . $matches[5] . '-' . $matches[6];
                } else {
                    preg_match('/[Bb]irth-date\\|(.*)\\}\\}/', $infoboxContents, $matches);
                    if ($matches[1] != '') {
                        $date = $matches[1];
                    } else {
                        preg_match('/\\|\\W*birth.date\\W*=\\W*(.*)/', $infoboxContents, $matches);
                        $date = $matches[1];
                    }
                }
                if (strpos($date, '=') || strpos($date, '{') || strpos($date, '}')) {
                    $date = '';
                }
                $fieldValue = $date;
            }
        }
        return $fieldValue;
    } else {
        if ($fieldInfo == '_name') {
            return $pageName;
        } elseif ($fieldInfo == '_url') {
            return $gImportWikiSubstring . str_replace(' ', '_', $pageName);
        } elseif ($fieldInfo == '_thumbnail') {
            $ret = $bot->query('?action=query&prop=pageimages&titles=' . urlencode($pageName) . '&format=php');
            $thumbnailURL = '';
            foreach ($ret['query']['pages'] as $pageInfo) {
                return $pageInfo['thumbnail']['source'];
            }
        } elseif ($fieldInfo == '_coordinates') {
            $ret = $bot->query('?action=query&prop=coordinates&titles=' . urlencode($pageName) . '&format=php');
            $coordinatesString = '';
            foreach ($ret['query']['pages'] as $pageInfo) {
                if (!array_key_exists('coordinates', $pageInfo)) {
                    break;
                }
                $coordinatesArray = $pageInfo['coordinates'][0];
                return $coordinatesArray['lat'] . ", " . $coordinatesArray['lon'];
            }
        } else {
            preg_match('/\\|[ ]*' . $fieldInfo . '[ ]*=[ ]*(.*)/', $infoboxContents, $matches);
            $fieldValue = $matches[1];
            $fieldValue = parseValue($fieldValue);
            return $fieldValue;
        }
    }
}