public function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = array(); $selected = array(); $a_selected = array(); $defaultValue = array(); $user_group_sid = SJB_Request::getVar('user_group_sid'); $id = SJB_Request::getVar('id', 0); $tree = ''; $username = ''; if ($id > 0) { // load exist parser $parser_from_id = SJB_XmlImport::getSystemParsers($id); if (isset($parser_from_id[0]['name'])) { $parser_from_id = $parser_from_id[0]; } $xml = $parser_from_id['xml']; $xml = SJB_XmlImport::cleanXmlFromImport($xml); $username = SJB_XmlImport::encodeSpecialEntities($parser_from_id['username']); $defaultValue = $parser_from_id['default_value_user'] != '' ? unserialize($parser_from_id['default_value_user']) : array(); if ($parser_from_id['maper_user'] != '') { $map = unserialize($parser_from_id['maper_user']); foreach ($map as $key => $val) { unset($map[$key]); $key = SJB_XmlImport::encodeSpecialEntities($key); $map[$key] = $val; } $selected = array_values($map); $a_selected = array_keys($map); } } else { $xml = SJB_XmlImport::cleanXmlFromImport(base64_decode($_REQUEST['xml'])); } $sxml = new simplexml(); $xml = stripslashes($xml); $tree = $sxml->xml_load_file($xml, 'array'); if (isset($tree['@content'])) { $tree = $tree[0]; } if (is_array($tree)) { $tree = SJB_XmlImport::convertArray($tree); foreach ($tree as $key => $val) { unset($tree[$key]); $key = SJB_XmlImport::encodeSpecialEntities($key); $tree[$key]['val'] = $val; $tree[$key]['key'] = $key; } $user_profile_fields = SJB_UserDetails::getDetails($user_group_sid); $i = count($user_profile_fields); foreach ($user_profile_fields as $key => $val) { if ($val['type'] == 'location') { foreach ($val['fields'] as $fieldInfo) { $userField = new SJB_UserProfileField($fieldInfo); $userField->setSID($fieldInfo['sid']); $user_profile_fields[$i]['id'] = $val['id'] . '_' . $userField->details->properties['id']->value; $user_profile_fields[$i]['caption'] = $userField->details->properties['id']->value; $i++; } unset($user_profile_fields[$key]); } if ($val['id'] == 'username') { unset($user_profile_fields[$key]); } } } else { $errors[] = 'XML syntaxis error.'; } $tp->assign('username', $username); $tp->assign('id', $id); $tp->assign('selecteduser', $selected); $tp->assign('a_selecteduser', $a_selected); $tp->assign('xml', htmlspecialchars($xml)); $tp->assign('errors', $errors); $tp->assign('tree', $tree); $tp->assign("fields", $user_profile_fields); $tp->assign('user_default_value', $defaultValue); $tp->display('user_fields.tpl'); }
/** * Perform normalization and analysis of MetaLib return value * (a single record) * * @param simplexml $record The xml record from MetaLib * * @return array The processed record array */ protected function process($record) { $record->registerXPathNamespace('m', 'http://www.loc.gov/MARC21/slim'); // TODO: can we get anything reliable from MetaLib results for format? $format = ''; $title = $this->getSingleValue($record, '245ab', ' : '); if ($addTitle = $this->getSingleValue($record, '245h')) { $title .= " {$addTitle}"; } $author = $this->getSingleValue($record, '100a'); $addAuthors = $this->getMultipleValues($record, '700a'); $sources = $this->getMultipleValues($record, 'SIDt'); $year = $this->getSingleValue($record, 'YR a'); $languages = $this->getMultipleValues($record, '041a'); $publishers = $this->getMultipleValues($record, '260b'); $urls = []; $res = $record->xpath("./m:datafield[@tag='856']"); foreach ($res as $value) { $value->registerXPathNamespace('m', 'http://www.loc.gov/MARC21/slim'); $url = $value->xpath("./m:subfield[@code='u']"); if ($url) { $desc = $value->xpath("./m:subfield[@code='y']"); if ($desc) { $urls[(string) $url[0]] = (string) $desc[0]; } else { $urls[(string) $url[0]] = (string) $url[0]; } } } $proxy = false; $ird = $this->getSingleValue($record, 'SIDd'); if ($ird) { $info = $this->getIRDInfo($ird); $proxy = $info['proxy'] == 'Y'; } $openurlParams = []; $opu = $this->getSingleValue($record, 'OPUa'); if ($opu) { $opuxml = simplexml_load_string($opu); $opuxml->registerXPathNamespace('ctx', 'info:ofi/fmt:xml:xsd:ctx'); $opuxml->registerXPathNamespace('rft', ''); //info:ofi/fmt:xml:xsd'); foreach ($opuxml->xpath('//*') as $element) { if (in_array($element->getName(), ['journal', 'author'])) { continue; } $value = trim((string) $element); if ($value) { $openurlParams[$element->getName()] = $value; // OpenURL might have many nicely parsed elements we can use switch ($element->getName()) { case 'date': if (empty($year)) { $year = $value; } break; case 'volume': $volume = $value; break; case 'issue': $issue = $value; break; case 'spage': $startPage = $value; break; case 'epage': $endPage = $value; break; } } } } $isbn = $this->getMultipleValues($record, '020a'); $issn = $this->getMultipleValues($record, '022a'); $snippet = $this->getMultipleValues($record, '520a'); $subjects = $this->getMultipleValues($record, '600abcdefghjklmnopqrstuvxyz' . ':610abcdefghklmnoprstuvxyz' . ':611acdefghjklnpqstuvxyz' . ':630adefghklmnoprstvxyz' . ':650abcdevxyz', ' : '); $notes = $this->getMultipleValues($record, '500a'); $field773g = $this->getSingleValue($record, '773g'); $matches = []; if (preg_match('/(\\d*)\\s*\\((\\d{4})\\)\\s*:\\s*(\\d*)/', $field773g, $matches)) { if (!isset($volume)) { $volume = $matches[1]; } if (!isset($issue)) { $issue = $matches[3]; } } elseif (preg_match('/(\\d{4})\\s*:\\s*(\\d*)/', $field773g, $matches)) { if (!isset($volume)) { $volume = $matches[1]; } if (!isset($issue)) { $issue = $matches[2]; } } if (preg_match('/,\\s*\\w\\.?\\s*([\\d,\\-]+)/', $field773g, $matches)) { $pages = explode('-', $matches[1]); if (!isset($startPage)) { $startPage = $pages[0]; } if (isset($pages[1]) && !isset($endPage)) { $endPage = $pages[1]; } } $hostTitle = explode('. ', $this->getSingleValue($record, '773t'), 2); $year = str_replace('^^^^', '', $year); return ['title' => $title, 'author' => $author ? $author : null, 'author2' => $addAuthors, 'source' => $sources[0], 'publisher' => $publishers, 'main_date_str' => $year ? $year : null, 'publishDate' => $year ? [$year] : null, 'container_title' => $hostTitle ? $hostTitle[0] : null, 'openUrl' => !empty($openurlParams) ? http_build_query($openurlParams) : null, 'url' => $urls, 'proxy' => $proxy, 'fullrecord' => $record->asXML(), 'id' => '', 'recordtype' => 'marc', 'format' => [$format], 'isbn' => $isbn, 'issn' => $issn, 'ispartof' => "{$hostTitle[0]}, {$field773g}", 'language' => $languages, 'topic' => $subjects, 'description' => $snippet, 'notes' => $notes, 'container_volume' => isset($volume) ? $volume : '', 'container_issue' => isset($issue) ? $issue : '', 'container_start_page' => isset($startPage) ? $startPage : '', 'container_end_page' => isset($endPage) ? $endPage : '']; }
public static function getListingsFromSimplyHired($params) { $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($params->listing_type_sid); if ($listingTypeID == 'Job' && $GLOBALS['uri'] == '/search-results-jobs/' || $GLOBALS['uri'] == '/ajax/') { $publisherID = SJB_Settings::getSettingByName('simplyHiredPublisherID'); $limit = SJB_Settings::getSettingByName('countSimplyHiredListings'); $ip = $_SERVER['REMOTE_ADDR']; $userAgent = urlencode(SJB_Request::getUserAgent()); $start = $limit * ($params->listing_search_structure['current_page'] - 1) + 1; $stateIndexes = array('AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming', 'DC' => 'District of Columbia', 'AS' => 'American Samoa', 'GU' => 'Guam', 'MP' => 'Northern Mariana Islands', 'PR' => 'Puerto Rico', 'UM' => "United's Minor Outlying Islands", 'VI' => 'Virgin Islands'); $countryCodes = array('United States' => 'us', 'Australia' => 'au', 'Austria' => 'at', 'Belgium' => 'be', 'Brazil' => 'br', 'Canada' => 'ca', 'France' => 'fr', 'Germany' => 'de', 'India' => 'in', 'Ireland' => 'ie', 'Italy' => 'it', 'Mexico' => 'mx', 'Netherlands' => 'nl', 'Spain' => 'es', 'Switzerland' => 'ch', 'United Kingdom' => 'gb'); // SET PARAMS FOR REQUEST $keywords = ''; $criteria = $params->criteria_saver->criteria; $fieldSID = SJB_ListingFieldManager::getListingFieldSIDByID('JobCategory'); $fieldInfo = SJB_ListingFieldDBManager::getListValuesBySID($fieldSID); $fieldList = array(); foreach ($fieldInfo as $val) { $fieldList[$val['id']] = $val['caption']; } $categoryCriteria = isset($criteria['JobCategory']['multi_like']) ? $criteria['JobCategory']['multi_like'] : ''; if (!empty($categoryCriteria)) { foreach ($categoryCriteria as $category) { if (!empty($fieldList[$category])) { $keywords .= empty($keywords) ? $fieldList[$category] : ' OR ' . $fieldList[$category]; } } if (!empty($keywords)) { $keywords = "({$keywords})"; } } foreach ($criteria as $field) { if (is_array($field)) { foreach ($field as $fieldType => $values) { if ($fieldType == 'multi_like_and') { foreach ($values as $val) { $keywords .= empty($keywords) ? $val : ' ' . $val; } } } } } if (isset($criteria['keywords']) && !empty($criteria['keywords'])) { foreach ($criteria['keywords'] as $key => $item) { if (in_array($key, array('exact_phrase', 'any_words', 'all_words', 'like'))) { $keywords .= $item; } } } $systemKeywords = trim(SJB_Settings::getSettingByName('simplyHiredKeyword')); $keywords = $systemKeywords ? '(' . $systemKeywords . ')' . ($keywords ? ' OR (' . $keywords . ')' : '') : $keywords; $keywords = preg_replace('/\\s+/', ' ', $keywords); $keywords = str_replace(',', '', $keywords); $keywords = urlencode(trim($keywords)); $location = self::getLocation($criteria, 'simplyHiredLocation'); $radius = SJB_Settings::getSettingByName('simplyHiredMiles'); if (isset($criteria['Location_ZipCode']['geo']['radius']) && !empty($criteria['Location_ZipCode']['geo']['radius'])) { $radius = $criteria['Location_ZipCode']['geo']['radius']; if ($radius == 'any') { $radius = ''; } } $sortBy = SJB_Settings::getSettingByName('simplyHiredSortBy'); $siteUrl = SJB_Settings::getSettingByName('simplyHiredSiteUrl'); $jobAMaticDomain = SJB_Settings::getSettingByName('jobAMaticDomain', false); if (!empty($jobAMaticDomain) && $siteUrl == 'simplyhired.com') { $jobAMaticDomain = str_replace('http://', '', $jobAMaticDomain); $jobAMaticDomain = str_replace('/', '', $jobAMaticDomain); $jobAMaticDomain = "&jbd={$jobAMaticDomain}"; } else { $jobAMaticDomain = ''; } if ($siteUrl == 'simplyhired.com') { $ssty = 2; } else { $ssty = 3; } $url = "http://api.{$siteUrl}/a/jobs-api/xml-v2/q-{$keywords}/l-{$location}/mi-{$radius}/ws-{$limit}/pn-{$params->listing_search_structure['current_page']}/sb-{$sortBy}?pshid={$publisherID}&ssty={$ssty}&cflg=r{$jobAMaticDomain}&clip={$ip}"; $sxml = new simplexml(); $xmlString = SJB_HelperFunctions::getUrlContentByCurl($url); $simplyhiredListings = array(); if ($xmlString === false) { // throw new Exception("simplyHiredPlugin: Failed to read XML from url - {$url}"); SJB_Logger::error("simplyHiredPlugin: Failed to read XML from url - {$url}"); } else { //$tree = $sxml->xml_load_file($url, 'array'); $tree = $sxml->xml_load_file($xmlString, 'array'); $totalResults = 0; if ($tree !== false) { $results = isset($tree['rs']) ? $tree['rs'] : array(); $outputCountry = array_flip($countryCodes); foreach ($results as $node) { if ($tree['rq']['rpd'] == 1) { $node = array($node); } foreach ($node as $key => $result) { $state = (string) $result['loc']['@attributes']['st']; $country = (string) $result['loc']['@attributes']['country']; $simplyhiredListings[$key] = array('Title' => (string) $result['jt'], 'CompanyName' => (string) isset($result['cn']['@content']) ? $result['cn']['@content'] : '', 'JobDescription' => (string) $result['e'], 'Location' => array('Country' => empty($country) ? '' : (isset($outputCountry[strtolower($country)]) ? $outputCountry[strtolower($country)] : ''), 'State' => empty($location[1]) ? '' : (isset($stateIndexes[strtoupper($state)]) ? $stateIndexes[strtoupper($state)] : ''), 'State_Code' => empty($state) ? '' : strtoupper($state), 'City' => (string) $result['loc']['@attributes']['cty']), 'activation_date' => (string) $result['dp'], 'url' => (string) $result['src']['@attributes']['url'], 'api' => 'simplyHired', 'onmousedown' => ' onMouseDown="xml_sclk(this);" ', 'target' => ' target="_blank"', 'onclick' => 'onclick="addStatisticsForSimplyHired();" ', 'code' => '<span style="font-size:10px; position:relative; top:-5px; font-family:Arial,sans-serif;color: #333;"><a style="color: #333; text-decoration:none" href="' . SJB_Request::getProtocol() . '://www.simplyhired.com/">Jobs</a> by</span> <a STYLE="text-decoration:none" href="' . SJB_Request::getProtocol() . '://www.simplyhired.com/"><img src="' . SJB_Request::getProtocol() . '://www.jobamatic.com/c/jbb/images/simplyhired.png" alt="Simply Hired"></a>'); } } } } self::$simplyhiredListings = $simplyhiredListings; } return $params; }
$input = $form->values(); $valid = !$form->has_errors(); // protect against CSRF attacks if ($ps->conf['main']['security']['csrf_protection']) { $valid = ($valid and $form->key_is_valid($cms->session)); } $list = array(); $valid = !$form->has_errors(); // process the XML and make sure it has valid data in it if ($valid) { $str = trim($input['xml']); $str = preg_replace('/^<\\?xml.+\\?>\\s*/', '', $str); if (substr($str, 0, 6) != '<maps>') { $str = "<maps>\n" . $str . "\n</maps>"; } $xml = new simplexml(); $ary = $xml->xml_load_string($str, 'array'); if (is_array($ary)) { if ($ary['map']) { $list = $ary['map'][0] ? $ary['map'] : array($ary['map']); } else { $form->error('fatal', $cms->trans("No valid 'map' nodes found! Make sure all 'map' nodes are contained with a root 'maps' node.")); } } else { if (substr($ary, 0, 15) == 'XML parse error') { // ary is an error string $form->error('fatal', $ary); } else { $form->error('fatal', "Invalid XML syntax!"); } }
function simplexml_load_string($file) { $sx = new simplexml(); return $sx->xml_load_string($file); }
/** * Perform normalization and analysis of MetaLib return value * (a single record) * * @param simplexml $record The xml record from MetaLib * * @return array The processed record array * @access protected */ protected function process($record) { global $configArray; $record->registerXPathNamespace('m', 'http://www.loc.gov/MARC21/slim'); // TODO: can we get anything reliable from MetaLib results for format? $format = ''; $title = $this->getSingleValue($record, '245ab', ' : '); if ($addTitle = $this->getSingleValue($record, '245h')) { $title .= " {$addTitle}"; } $author = $this->getSingleValue($record, '100a'); $addAuthors = $this->getSingleValue($record, '700a'); $sources = $this->getMultipleValues($record, 'SIDt'); $year = $this->getSingleValue($record, 'YR a'); $languages = $this->getMultipleValues($record, '041a'); $urls = array(); $res = $record->xpath("./m:datafield[@tag='856']"); foreach ($res as $value) { $value->registerXPathNamespace('m', 'http://www.loc.gov/MARC21/slim'); $url = $value->xpath("./m:subfield[@code='u']"); if ($url) { $desc = $value->xpath("./m:subfield[@code='y']"); if ($desc) { $urls[(string) $url[0]] = (string) $desc[0]; } else { $urls[(string) $url[0]] = (string) $url[0]; } } } $proxy = false; $ird = $this->getSingleValue($record, 'SIDd'); if ($ird) { $info = $this->getIRDInfo($ird); $proxy = $info['proxy'] == 'Y'; } $openurl = array(); if (isset($configArray['OpenURL']['url']) && $configArray['OpenURL']['url']) { $opu = $this->getSingleValue($record, 'OPUa'); if ($opu) { $opuxml = simplexml_load_string($opu); $opuxml->registerXPathNamespace('ctx', 'info:ofi/fmt:xml:xsd:ctx'); $opuxml->registerXPathNamespace('rft', ''); //info:ofi/fmt:xml:xsd'); foreach ($opuxml->xpath('//*') as $element) { if (in_array($element->getName(), array('journal', 'author'))) { continue; } $value = trim((string) $element); if ($value) { $openurl[$element->getName()] = $value; // OpenURL might have many nicely parsed elements we can use switch ($element->getName()) { case 'date': if (empty($year)) { $year = $value; } break; case 'volume': $volume = $value; break; case 'issue': $issue = $value; break; case 'spage': $startPage = $value; break; case 'epage': $endPage = $value; break; } } } if (!empty($openurl)) { $openurl['rfr_id'] = $configArray['OpenURL']['rfr_id']; } } } $isbn = $this->getMultipleValues($record, '020a'); $issn = $this->getMultipleValues($record, '022a'); $snippet = $this->getMultipleValues($record, '520a'); $subjects = $this->getMultipleValues($record, '600abcdefghjklmnopqrstuvxyz' . ':610abcdefghklmnoprstuvxyz' . ':611acdefghjklnpqstuvxyz' . ':630adefghklmnoprstvxyz' . ':650abcdevxyz', ' : '); $notes = $this->getMultipleValues($record, '500a'); $field773g = $this->getSingleValue($record, '773g'); $matches = array(); if (preg_match('/(\\d*)\\s*\\((\\d{4})\\)\\s*:\\s*(\\d*)/', $field773g, $matches)) { if (!isset($volume)) { $volume = $matches[1]; } if (!isset($issue)) { $issue = $matches[3]; } } elseif (preg_match('/(\\d{4})\\s*:\\s*(\\d*)/', $field773g, $matches)) { if (!isset($volume)) { $volume = $matches[1]; } if (!isset($issue)) { $issue = $matches[2]; } } if (preg_match('/,\\s*\\w\\.?\\s*([\\d,\\-]+)/', $field773g, $matches)) { $pages = explode('-', $matches[1]); if (!isset($startPage)) { $startPage = $pages[0]; } if (isset($pages[1]) && !isset($endPage)) { $endPage = $pages[1]; } } $hostTitle = $this->getSingleValue($record, '773t'); if ($hostTitle && $field773g) { $hostTitle .= " {$field773g}"; } $year = str_replace('^^^^', '', $year); return array('Title' => array($title), 'Author' => $author ? array($author) : null, 'AdditionalAuthors' => $addAuthors, 'Source' => $sources, 'PublicationDate' => $year ? array($year) : null, 'PublicationTitle' => $hostTitle ? array($hostTitle) : null, 'openUrl' => !empty($openurl) ? http_build_query($openurl) : null, 'url' => $urls, 'proxy' => $proxy, 'fullrecord' => $record->asXML(), 'id' => '', 'recordtype' => 'marc', 'format' => array($format), 'ISBN' => $isbn, 'ISSN' => $issn, 'Language' => $languages, 'SubjectTerms' => $subjects, 'Snippet' => $this->snippets ? $snippet : null, 'Notes' => $notes, 'Volume' => isset($volume) ? $volume : '', 'Issue' => isset($issue) ? $issue : '', 'StartPage' => isset($startPage) ? $startPage : '', 'EndPage' => isset($endPage) ? $endPage : ''); }
public function execute() { $errors = array(); if (SJB_Request::isAjax()) { $response = null; if ($logoId = SJB_Request::getVar('logo_id')) { SJB_UploadFileManager::deleteUploadedFileByID($logoId, 'logo'); $parsersId = SJB_Request::getVar('id'); SJB_DB::query("UPDATE `parsers` SET `xml_logo` = NULL WHERE id = ?n", $parsersId); } elseif ($userName = SJB_Request::getVar('parser_user')) { $userType = SJB_Request::getVar('user_type'); $products = SJB_XmlImport::getProducts($userType, $userName, $errors); $response = array('products' => empty($products) ? '' : SJB_XmlImport::translateProductsName($products), 'error' => empty($errors) ? '' : array_pop($errors)); $response = json_encode($response); } die($response); } $tp = SJB_System::getTemplateProcessor(); $original_xml = !empty($_REQUEST['xml']) ? $_REQUEST['xml'] : ''; $xml = $original_xml; $tree = ''; $listing_fields = array(); $parsing_name = isset($_REQUEST['parser_name']) ? $_REQUEST['parser_name'] : ''; $usr_name = isset($_REQUEST['parser_user']) ? $_REQUEST['parser_user'] : ''; $pars_url = isset($_REQUEST['parser_url']) ? $_REQUEST['parser_url'] : ''; $form_description = isset($_POST['form_description']) ? $_POST['form_description'] : ""; $type_id = isset($_POST['type_id']) ? intval($_POST['type_id']) : ""; $custom_script = SJB_Request::getVar('custom_script', ''); $custom_script_users = SJB_Request::getVar('custom_script_users', ''); $add_new_user = isset($_POST['add_new_user']) ? intval($_POST['add_new_user']) : 0; $username = SJB_Request::getVar('username', ''); $external_id = SJB_Request::getVar('external_id', ''); $defaultValue = array(); $logo_options_array = array('not_logo' => 'Do Not Import Logo', 'import_logo' => 'Import Logo with Listings', 'upload_logo' => 'Upload Logo for Imported Listings'); $id = isset($_GET['id']) ? intval($_GET['id']) : 0; $selected = array(); $a_selected = array(); $selectedLogoOption = null; $selectedLogoField = null; $xml_logo = null; $selectedProduct = SJB_Request::getVar('postUnderProduct'); $save_error = SJB_Request::getVar('save_error'); if ($save_error) { $errors[] = base64_decode($save_error); } if (!empty($_REQUEST['xml']) || $id > 0) { // step 2 OR edit exist if ($id > 0) { // load exist parser $parser_from_id = SJB_XmlImport::getSystemParsers($id); if (isset($parser_from_id[0]['name'])) { $parser_from_id = $parser_from_id[0]; } $parsing_name = $parser_from_id['name']; $usr_id = $parser_from_id['usr_id']; $usr_name = $parser_from_id['usr_name']; $form_description = $parser_from_id['description']; $pars_url = $parser_from_id['url']; $type_id = $parser_from_id['type_id']; $custom_script = $parser_from_id['custom_script']; $custom_script_users = $parser_from_id['custom_script_users']; $add_new_user = $parser_from_id['add_new_user']; $importType = $parser_from_id['import_type']; $xml = $parser_from_id['xml']; $xml_logo = $parser_from_id['xml_logo']; $xml = SJB_XmlImport::cleanXmlFromImport($xml); $defaultValue = $parser_from_id['default_value'] != '' ? unserialize($parser_from_id['default_value']) : array(); $username = $parser_from_id['username']; $map = unserialize($parser_from_id['maper']); $external_id = str_replace('@', '_dog_', $parser_from_id['external_id']); $selected_logo_options = unserialize($parser_from_id['logo_options']); $selectedLogoOption = $selected_logo_options['option']; $selectedLogoField = $selected_logo_options['field']; if ($selected_logo_options['option'] == 'upload_logo') { $upload_manager = new SJB_UploadPictureManager(); $upload_manager->getUploadedPictureInfo($xml_logo . '_thumb'); $logo_link = $upload_manager->getUploadedFileLink($xml_logo . '_thumb'); $tp->assign('logo_link', $logo_link); } foreach ($map as $key => $val) { unset($map[$key]); $key = SJB_XmlImport::encodeSpecialEntities($key); $map[$key] = $val; } $selected = array_values($map); $a_selected = array_keys($map); $selectedProduct = $parser_from_id['product_sid']; } else { $xml = SJB_XmlImport::cleanXmlFromImport($_REQUEST['xml']); } $sxml = new simplexml(); $xml = stripslashes($xml); $tree = $sxml->xml_load_file($xml, 'array'); if (isset($tree['@content'])) { $tree = $tree[0]; } if (is_array($tree)) { $tree = SJB_XmlImport::convertArray($tree); foreach ($tree as $key => $val) { unset($tree[$key]); $key = SJB_XmlImport::encodeSpecialEntities($key); $tree[$key]['val'] = $val; $tree[$key]['key'] = $key; } $field_types = array(0, $type_id); $listing_fields = array(); $i = 0; foreach ($field_types as $type) { $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($type); foreach ($listing_fields_info as $listing_field_info) { if ($listing_field_info['type'] == 'location') { foreach ($listing_field_info['fields'] as $fieldInfo) { $listing_field = new SJB_ListingField($fieldInfo); $listing_field->setSID($fieldInfo['sid']); $listing_fields[$i]['id'] = $listing_field_info['id'] . '_' . $listing_field->details->properties['id']->value; $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value; $i++; } } else { $listing_field = new SJB_ListingField($listing_field_info); $listing_field->setSID($listing_field_info['sid']); $listing_fields[$i]['id'] = $listing_field->details->properties['id']->value; $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value; $i++; } } } $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "date"; $i++; $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "url"; $i++; $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "external_id"; } else { $errors[] = 'XML syntaxis error.'; } } else { $errors[] = 'Please input correct xml'; } if (empty($selectedProduct)) { $errors[] = 'Please select a product'; } if (!filter_var($pars_url, FILTER_VALIDATE_URL)) { $errors[] = 'Please input correct URL'; } $error = SJB_Request::getVar('error', false, 'GET'); if ($error) { $errors[$error] = true; } $userType = empty($add_new_user) ? 'username' : 'group'; if ($userType == 'group') { $userName = SJB_UserGroupManager::getUserGroupSIDByID($usr_name); } else { $userName = $usr_name; } $products = SJB_XmlImport::getProducts($userType, $userName, $errors); $tp->assign('id', $id); $tp->assign('selected', $selected); $tp->assign('a_selected', $a_selected); $tp->assign('xml', htmlspecialchars($xml)); $tp->assign('xml_logo', $xml_logo); $tp->assign('xmlToUser', $xml); $tp->assign('default_value', $defaultValue); $tp->assign('form_name', $parsing_name); $tp->assign('form_user', $usr_name); $tp->assign('form_user_sid', $usr_id); $tp->assign('form_url', $pars_url); $tp->assign('form_description', $form_description); $tp->assign('custom_script', $custom_script); $tp->assign('custom_script_users', $custom_script_users); $tp->assign('username', $username); $tp->assign('external_id', $external_id); $tp->assign('import_type', $importType); $tp->assign('user_groups', SJB_UserGroupManager::getAllUserGroupsInfo()); $type_name = SJB_ListingTypeManager::getListingTypeIDBySID($type_id); $tp->assign('add_new_user', $add_new_user); $tp->assign('type_id', $type_id); $tp->assign('type_name', $type_name); $tp->assign('errors', $errors); $tp->assign('tree', $tree); $tp->assign("fields", $listing_fields); $tp->assign('logo_options', $logo_options_array); $tp->assign('selectedLogoOption', $selectedLogoOption); $tp->assign('selectedLogoField', $selectedLogoField); $tp->assign('selectedProduct', $selectedProduct); $tp->assign('products', $products); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display('add_step_two.tpl'); }
/** * Perform normalization and analysis of PCI return value * (a single record) * * @param simplexml $item The xml record from PCI * * @return array The processed record array * @access protected */ protected function process($item) { global $configArray; $primoRecord = $item->children('http://www.exlibrisgroup.com/xsd/primo/primo_nm_bib'); $links = array(); $backlink = ''; foreach ((array) $primoRecord->PrimoNMBib->record->links->linktorsrc as $val) { $linkString = (string) $val; $ini = strripos($linkString, '$$U'); if ($ini === false) { continue; } $ini += 3; $linkArray = explode('$$', substr($linkString, $ini)); if ($linkArray[0]) { $links[] = $linkArray[0]; } } // Back links sometimes contain non-valid XML and thus cannot // be treated like source links $backlinkString = (string) $primoRecord->PrimoNMBib->record->links->backlink; $ini = strripos($backlinkString, '$$U'); if ($ini !== false) { $ini += 3; $backlinkArray = explode('$$', substr($backlinkString, $ini)); if ($backlinkArray[0]) { $backlink = $backlinkArray[0]; } } $openurl = ''; if (isset($configArray['OpenURL']['url']) && $configArray['OpenURL']['url']) { // Parse the OpenURL and extract parameters $link = $item->xpath('.//sear:LINKS/sear:openurl'); if (!$link) { $link = $item->xpath('.//sear:GETIT/@GetIt2'); if (!$link || $link[0] == "") { $link = $item->xpath('.//sear:GETIT/@GetIt1'); } } if ($link && strpos($link[0], 'url_ver=Z39.88-2004') !== false) { $params = explode('&', substr($link[0], strpos($link[0], '?') + 1)); $openurl = 'rfr_id=' . urlencode($configArray['OpenURL']['rfr_id']); foreach ($params as $param) { if (substr($param, 0, 7) != 'rfr_id=') { $openurl .= '&' . $param; } } } } $fulltext = (string) $primoRecord->PrimoNMBib->record->delivery->fulltext; $title = $this->hiLite((string) $primoRecord->PrimoNMBib->record->display->title); $authors = explode(' ; ', (string) $primoRecord->PrimoNMBib->record->display->creator); foreach ($authors as &$author) { $author = $this->hiLite($author); } return array('title' => $title, 'author' => $authors, 'AdditionalAuthors' => (array) $primoRecord->PrimoNMBib->record->search->creatorcontrib, 'source' => (string) $primoRecord->PrimoNMBib->record->display->source, 'publicationDate' => (string) $primoRecord->PrimoNMBib->record->search->creationdate, 'publicationTitle' => (string) $primoRecord->PrimoNMBib->record->display->ispartof, 'openUrl' => !empty($openurl) ? $openurl : null, 'url' => $links, 'backlink' => $backlink, 'fulltext' => $fulltext, 'fullrecord' => $item->asXML(), 'id' => 'pci.' . (string) $primoRecord->PrimoNMBib->record->search->recordid, 'format' => (string) $primoRecord->PrimoNMBib->record->display->type, 'ISSN' => (string) $primoRecord->PrimoNMBib->record->search->issn, 'language' => (string) $primoRecord->PrimoNMBib->record->facets->language, 'subjectTerms' => (array) $primoRecord->PrimoNMBib->record->search->subject, 'snippet' => (string) $primoRecord->PrimoNMBib->record->display->description, 'volume' => (string) $primoRecord->PrimoNMBib->record->addata->volume, 'issue' => (string) $primoRecord->PrimoNMBib->record->addata->issue, 'startPage' => '', 'endPage' => ''); }
* amazon search * */ require_once 'res/simplexml.class.php'; // include('res/url_get_contents.php'); //for older php versions function searchAmazon($country, $artistName, $albumName) { if ($country == "DE") { $country = "de"; } $accessKeyId = ""; // aws id $secretKey = ""; // aws secret key $associateTag = ""; // affiliate tag if ($albumName == "") { $Keywords = $artistName; } else { $Keywords = $artistName . " " . $albumName; } $Timestamp = gmdate("Y-m-d\\TH:i:s\\Z"); $ResponseGroup = "ItemAttributes"; $ResponseGroup = str_replace(",", "%2C", $ResponseGroup); $Keywords = str_replace(" ", "+", $Keywords); $Keywords = str_replace("&", " ", $Keywords); $params = "AWSAccessKeyId={$accessKeyId}&\r\r\nAssociateTag={$associateTag}&\r\r\nKeywords={$Keywords}&\r\r\nOperation=ItemSearch&\r\r\nSearchIndex=MP3Downloads&\r\r\nItemPage=1&\r\r\nResponseGroup={$ResponseGroup}&\r\r\nService=AWSECommerceService&\r\r\nTimestamp={$Timestamp}&\r\r\nVersion=2013-08-01"; $BaseUrl = "http://webservices.amazon." . $country . "/onca/xml?"; $params = $BaseUrl . $params; $params = str_replace("%7E", "~", $params); $params = preg_replace('/[\\r\\n\\" "]/', '', $params); $params = preg_replace('/[" "]+/', ' ', $params); $paramsArray = explode('?', $params, 2); $Parameters = explode("&", $paramsArray[1]); asort($Parameters); $NewString = implode("&", $Parameters); $NewString = rawurlencode($NewString); $NewString = str_replace("~", "%7E", $NewString); $NewString = str_replace("%3D", "=", $NewString); $NewString = str_replace("%26", "&", $NewString); $NewString = str_replace("%FA", "%C3%BA", $NewString); // ú $NewString = str_replace("%E9", "%C3%A9", $NewString); // é $NewString = str_replace("%F6", "%C3%B6", $NewString); // ö $NewString = str_replace("%E1", "%C3%A1", $NewString); // á $NewString = str_replace("%F3", "%C3%B3", $NewString); // ó $NewString = str_replace("%FC", "%C3%BC", $NewString); // ü $NewString = str_replace("%E4", "%C3%A4", $NewString); // ä $url = parse_url($paramsArray[0]); $PrependString = "GET\n" . $url['host'] . "\n" . $url['path'] . "\n" . $NewString; $Signature = base64_encode(hash_hmac('sha256', $PrependString, $secretKey, true)); $Signature = rawurlencode($Signature); $SignedRequest = $paramsArray[0] . "?" . $NewString . "&Signature=" . $Signature; $file = $SignedRequest; $sxml = new simplexml(); $dataa = $sxml->xml_load_file($file); $resCount = (int) $dataa->Items->TotalResults; //$amz_err = $dataa->Items->Request->Errors->Error->Code; $amazon_url = $dataa->Items->MoreSearchResultsUrl; if ($resCount == 0) { $res = "empty"; } elseif ($resCount > 0) { $res = array($amazon_url);
/** * Extract facets from the Solr response * * @param simplexml $xml solr response * @return Facets, null if none */ protected function extractFacets($xml) { $facets = new Search\Facets(); $groups = $xml->xpath("//lst[@name='facet_fields']/lst"); if ($groups !== false && count($groups) > 0) { foreach ($groups as $facet_group) { // if only one entry, then all the results have this same facet, // so no sense even showing this as a limit $count = count($facet_group->int); if ($count <= 1) { continue; } $group_internal_name = (string) $facet_group["name"]; $group = new Search\FacetGroup(); $group->name = $group_internal_name; $group->public = $this->config->getFacetPublicName($group_internal_name); // put facets into an array $facet_array = array(); foreach ($facet_group->int as $int) { $facet_array[(string) $int["name"]] = (int) $int; } // date $decade_display = array(); $is_date = $this->config->isDateType($group_internal_name); if ($is_date == true) { $date_arrays = $group->luceneDateToDecade($facet_array); $decade_display = $date_arrays["display"]; $facet_array = $date_arrays["decades"]; } foreach ($facet_array as $key => $value) { $facet = new Search\Facet(); $facet->name = $key; $facet->count = $value; // dates are different if ($is_date == true) { $facet->name = $decade_display[$key]; $facet->is_date = true; $facet->key = $key; } $group->addFacet($facet); } $facets->addGroup($group); } } return $facets; }
/** * Extract facets from the Solr response * * @param simplexml $xml solr response * @return Facets null if none */ protected function extractFacets($xml) { $facets = new Search\Facets(); $groups = $xml->xpath("//lst[@name='facet_fields']/lst"); if ($groups !== false && count($groups) > 0) { foreach ($groups as $facet_group) { // if only one entry, then all the results have this same facet, // so no sense even showing this as a limit $count = count($facet_group->int); if ($count <= 1) { continue; } $group_internal_name = (string) $facet_group["name"]; $group = new Search\FacetGroup(); $group->name = $group_internal_name; // put facets into an array $facet_array = array(); foreach ($facet_group->int as $int) { $facet_array[(string) $int["name"]] = (int) $int; } $is_date = $this->config->isDateType($group_internal_name); foreach ($facet_array as $key => $value) { $facet = new Search\Facet(); $facet->name = $key; $facet->count = $value; if ($is_date == true) { $facet->is_date = true; $facet->timestamp = strtotime("1/1/{$key}") * 1000; } $group->addFacet($facet); } $facets->addGroup($group); } } return $facets; }
#----------------------------------------- CUSTOM USER CONFIGURATION -----------------------------------------------# $serverTitle = "SWGemu Test Centre"; #Edit this field with your server's name. It can be anything you wish.# $serverAddress = "chicago2.swgemu.com"; #Edit this field with your Core3 server's IP address or hostname.# #------------------------------------------ DO NOT EDIT BELOW THIS LINE -------------------------------------------# $port = 44455; require "simplexml.class.php"; $fp = @fsockopen("tcp://" . $serverAddress, $port, $errno, $errstr); if (!$fp) { $status = "down"; } else { fwrite($fp, "\n"); $xml = fread($fp, 99999); fclose($fp); $sxml = new simplexml(); $xmldata = $sxml->xml_load_data($xml); $status = $xmldata->status; } if ($status == "down") { $now = date("D, d M Y H:i:s T"); $output = "<?xml version=\"1.0\"?>\r\n <rss version=\"2.0\">\r\n <channel>\r\n <title>{$serverTitle} Status</title>\r\n <link>http://www.swgemu.com/</link>\r\n <description>Live, Up to date server status for {$serverTitle}.</description>\r\n <language>en-us</language>\r\n <pubDate>{$now}</pubDate>\r\n <lastBuildDate>{$now}</lastBuildDate>\r\n <docs>http://support.swgemu.com</docs>\r\n <managingEditor>Maximilius-CSR@gmail.com</managingEditor>\r\n <webMaster>Maximilius-CSR@gmail.com</webMaster>\r\n "; $output .= "<item><title>{$serverTitle}: OFFLINE</title>\r\n <link>http://support.swgemu.com</link>\r\n \r\n<description>The automatic server status reads as OFFLINE.</description>\r\n </item>"; $output .= "</channel></rss>"; header("Content-Type: application/rss+xml"); echo $output; exit(1); } $now = date("D, d M Y H:i:s T"); $output = "<?xml version=\"1.0\"?>\r\n <rss version=\"2.0\">\r\n <channel>\r\n <title>{$serverTitle} Status</title>\r\n <link>http://www.swgemu.com/</link>\r\n <description>Live, Up to date Status report for {$serverTitle}</description>\r\n <language>en-us</language>\r\n <pubDate>{$now}</pubDate>\r\n <lastBuildDate>{$now}</lastBuildDate>\r\n <docs>http://support.swgemu.com</docs>\r\n <managingEditor>Maximilius-CSR@gmail.com</managingEditor>\r\n <webMaster>Maximilius-CSR@gmail.com</webMaster>\r\n "; $output .= "<item><title>{$serverTitle}: ONLINE</title>\r\n <link>http://support.swgemu.com</link>\r\n \r\n<description>\r\nThe server is " . $status . ". \r\nThere are " . $xmldata->users->connected . " Users Connected.\r\nThis was gathered on " . date("F j, Y, g:i:s a", $xmldata->timestamp) . ".\r\n</description>\r\n </item>";
function UpdateModuleSettings($filename, $moduleID, $pageName = false, $templateName = false, $duplicateID = 0) { global $wpdb; $whereCond = " WHERE module_id = '{$moduleID}' "; if ($templateName) { $whereCond .= " AND theme = '{$templateName}'"; } if ($pageName) { $whereCond .= " AND page='{$pageName}'"; } if ($duplicateID > 0) { $whereCond .= " AND duplicate_id='{$duplicateID}'"; } //if (!$templateName) $templateName = get_option('template'); if (!file_exists($filename)) { return false; } $themeSettings = new simplexml(); $themeSettings->xml_load_file($filename); $themeSettings = $themeSettings->result; // Add a module row $themeSettingsIDs = $wpdb->get_col("SELECT block_id FROM " . FLUTTER_TABLE_LAYOUT_MODULES . $whereCond); if (empty($themeSettingsIDs)) { if (!$templateName) { $templateName = get_option('template'); } if (!$pageName) { $pageName = "index.php"; } $wpdb->query("INSERT INTO " . FLUTTER_TABLE_LAYOUT_MODULES . " (theme, module_id, page, duplicate_id) VALUES ('{$templateName}', '{$moduleID}', '{$pageName}', '{$duplicateID}')"); $themeSettingsIDs[0] = $wpdb->insert_id; } foreach ($themeSettingsIDs as $themeSettingsID) { // Import variables if (!empty($themeSettings['variables'])) { foreach ($themeSettings['variables'][0]['variable'] as $variable) { // --- Add/Update Variable $name = trim(str_replace(array(' ', '.'), '_', addslashes(array_pop($variable['name'])))); $type = trim(array_pop($variable['type'])); $description = trim(addslashes(array_pop($variable['description']))); // default value $default = $variable['default']; if (!empty($default)) { $default = array_pop($variable['default']); if ($type == 'checkbox_list' || $type == 'listbox') { $defaultArray = array(); foreach ($default['value'] as $value) { $defaultArray[] = trim($value); } $default = addslashes(serialize($defaultArray)); } else { $default = trim(addslashes($default)); } } else { $default = ''; } // options $options = $variable['options']; if (!empty($options)) { $options = array_pop($variable['options']); $optionsArray = array(); if (isset($options['dbvalue'])) { $optionsArray = $options; } else { foreach ($options['value'] as $value) { $optionsArray[] = trim($value); } } $options = addslashes(serialize($optionsArray)); } else { $options = ''; } $variableID = $wpdb->get_var("SELECT variable_id FROM " . FLUTTER_TABLE_LAYOUT_VARIABLES . " WHERE variable_name = '{$name}' AND parent = '{$themeSettingsID}'"); if (empty($variableID)) { $wpdb->query("INSERT INTO " . FLUTTER_TABLE_LAYOUT_VARIABLES . " (variable_name,parent,type,value,default_value,description,options) VALUES ('{$name}','{$themeSettingsID}','{$type}','{$default}','{$default}','{$description}','{$options}')"); $variableID = $wpdb->insert_id; } else { $wpdb->query("UPDATE " . FLUTTER_TABLE_LAYOUT_VARIABLES . " SET type = '{$type}', default_value = '{$default}', description = '{$description}' , options='{$options}' " . " WHERE variable_id = '{$variableID}' "); } } } // -- Delete obselete variables $blockVars = $wpdb->get_results("SELECT * FROM " . FLUTTER_TABLE_LAYOUT_VARIABLES . " WHERE parent = '{$themeSettingsID}'"); foreach ($blockVars as $blockVar) { $found = false; if (!empty($themeSettings['variables'])) { foreach ($themeSettings['variables'][0]['variable'] as $variable) { $name = trim(str_replace(array(' ', '.'), '_', addslashes(array_pop($variable['name'])))); if ($name == $blockVar->variable_name) { $found = true; } } } if (!$found) { $wpdb->query("DELETE FROM " . FLUTTER_TABLE_LAYOUT_VARIABLES . " WHERE variable_id = " . $blockVar->variable_id); } } } return $themeSettingsIDs; }
public function execute() { $errors = array(); if (SJB_Request::isAjax()) { $response = null; $user_type = SJB_Request::getVar('user_type'); $user_name = SJB_Request::getVar('parser_user'); $products = SJB_XmlImport::getProducts($user_type, $user_name, $errors); $response = array('products' => empty($products) ? '' : SJB_XmlImport::translateProductsName($products), 'error' => empty($errors) ? '' : array_pop($errors)); die(json_encode($response)); } $tp = SJB_System::getTemplateProcessor(); $add_level = SJB_Request::getVar('add_level', 1); // check for errors if ($add_level == '3') { $selectUserType = SJB_Request::getVar('selectUserType'); $addNewUser = 0; if ($selectUserType == 'username') { $usr_name = isset($_REQUEST['parser_user']) ? SJB_DB::quote($_REQUEST['parser_user']) : ''; $usr_id = SJB_UserManager::getUserSIDbyUsername($usr_name); if (empty($usr_name)) { $errors[] = 'Please enter user name of existing user to the "User Name" field'; $usr_name = ''; } else { $user_sid_exists = SJB_UserManager::getUserSIDbyUsername($usr_name); if (empty($user_sid_exists)) { $errors[] = 'User "' . $usr_name . '" not exists. Please enter user name of existing user to the "User Name" field'; $usr_name = ''; } } } elseif ($selectUserType == 'group') { $userGroupSid = isset($_REQUEST['parser_user']) ? $_REQUEST['parser_user'] : 0; $usr_id = $userGroupSid; $usr_name = SJB_UserGroupManager::getUserGroupIDBySID($usr_id); $addNewUser = 1; } if ($errors) { $add_level = 2; } } $listings_type = SJB_ListingTypeManager::getAllListingTypesInfo(); $types = array(); foreach ($listings_type as $one) { $types[$one['sid']] = $one['id']; } $tp->assign('types', $types); $selected_logo_options = null; switch ($add_level) { case '1': $template = 'add_step_one.tpl'; /* $types = array(); foreach ( $listings_type as $one ) { $types[$one['sid']] = $one['id']; } $tp->assign('types', $types); */ $tp->display('add_step_one.tpl'); break; case '2': $template = 'add_step_two.tpl'; $original_xml = SJB_Request::getVar('xml'); $xml = $original_xml; $tree = ''; $listing_fields = array(); $logo_options_array = array('not_logo' => 'Do Not Import Logo', 'import_logo' => 'Import Logo with Listings', 'upload_logo' => 'Upload Logo for Imported Listings'); $parsing_name = SJB_Request::getVar('parser_name'); $usr_name = SJB_Request::getVar('parser_user'); $pars_url = SJB_Request::getVar('parser_url'); $form_description = SJB_Request::getVar('form_description', '', 'POST'); $type_id = SJB_Request::getVar('type_id', '', 'POST'); $selectedLogoOption = SJB_Request::getVar('logo_options'); $selectedLogoField = SJB_Request::getVar('import_logo_field'); $selectedProduct = SJB_Request::getVar('postUnderProduct'); $id = SJB_Request::getVar('id', 0, 'GET'); $selected = array(); $a_selected = array(); if (!empty($_REQUEST['xml']) || $id > 0) { // step 2 OR edit exist if ($id > 0) { // load exist parser $parser_from_id = SJB_XmlImport::getSystemParsers($id); if (isset($parser_from_id[0]['name'])) { $parser_from_id = $parser_from_id[0]; } $parsing_name = $parser_from_id['name']; $usr_id = $parser_from_id['usr_id']; $usr_name = $parser_from_id['usr_name']; $form_description = $parser_from_id['description']; $pars_url = $parser_from_id['url']; $type_id = $parser_from_id['type_id']; $selected_logo_options = unserialize($parser_from_id['logo_options']); $selectedLogoOption = $selected_logo_options['option']; $selectedLogoField = $selected_logo_options['field']; $selectedProduct = $parser_from_id['product_sid']; $xml = $parser_from_id['xml']; $xml = SJB_XmlImport::cleanXmlFromImport($xml); $map = unserialize($parser_from_id['maper']); $selected = array_values($map); $a_selected = array_keys($map); } else { $xml = SJB_XmlImport::cleanXmlFromImport($_REQUEST['xml']); } $sxml = new simplexml(); $tree = $sxml->xml_load_file($xml, 'array'); if (isset($tree['@content'])) { $tree = $tree[0]; } if (is_array($tree)) { $tree = SJB_XmlImport::convertArray($tree); foreach ($tree as $key => $val) { unset($tree[$key]); // replace '@' and ':' $key = SJB_XmlImport::encodeSpecialEntities($key); $tree[$key]['val'] = $val; $tree[$key]['key'] = $key; } $field_types = array(0, $type_id); $listing_fields = array(); $i = 0; foreach ($field_types as $type) { $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($type); foreach ($listing_fields_info as $listing_field_info) { if ($listing_field_info['type'] == 'location') { foreach ($listing_field_info['fields'] as $fieldInfo) { $listing_field = new SJB_ListingField($fieldInfo); $listing_field->setSID($fieldInfo['sid']); $listing_fields[$i]['id'] = $listing_field_info['id'] . '_' . $listing_field->details->properties['id']->value; $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value; $i++; } } else { $listing_field = new SJB_ListingField($listing_field_info); $listing_field->setSID($listing_field_info['sid']); $listing_fields[$i]['id'] = $listing_field->details->properties['id']->value; $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value; $i++; } } } $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "date"; $i++; $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "url"; $i++; $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "external_id"; } else { $errors[] = 'XML syntaxis error.'; $template = 'add_step_one.tpl'; } } else { $errors[] = 'Please input correct xml'; $template = 'add_step_one.tpl'; } $tp->assign('id', $id); $tp->assign('selected', $selected); $tp->assign('a_selected', $a_selected); $tp->assign('xml', htmlspecialchars($xml)); $tp->assign('xmlToUser', $xml); $tp->assign('user_groups', SJB_UserGroupManager::getAllUserGroupsInfo()); $tp->assign('form_name', $parsing_name); $tp->assign('form_user', $usr_name); $tp->assign('form_url', $pars_url); $tp->assign('form_description', $form_description); $type_name = SJB_ListingTypeManager::getListingTypeIDBySID($type_id); $tp->assign('type_id', $type_id); $tp->assign('type_name', $type_name); $tp->assign('errors', $errors); $tp->assign('tree', $tree); $tp->assign("fields", $listing_fields); $tp->assign('logo_options', $logo_options_array); $tp->assign('selectedLogoOption', $selectedLogoOption); $tp->assign('selectedLogoField', $selectedLogoField); $tp->assign('selectedProduct', $selectedProduct); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display($template); break; case '3': $parsing_name = isset($_REQUEST['parser_name']) ? SJB_DB::quote($_REQUEST['parser_name']) : ''; $pars_url = isset($_POST['parser_url']) ? SJB_DB::quote($_POST['parser_url']) : ''; $selectedLogoOption = isset($_POST['logo_options']) ? $_POST['logo_options'] : ''; $selectedLogoField = isset($_POST['import_logo_field']) ? $_POST['import_logo_field'] : ''; $form_description = isset($_REQUEST['form_description']) ? SJB_DB::quote($_REQUEST['form_description']) : ""; $type_id = isset($_POST['type_id']) ? intval($_POST['type_id']) : ""; $script = isset($_POST['custom_script']) && !empty($_POST['custom_script']) ? SJB_DB::quote($_POST['custom_script']) : ""; $script_users = SJB_DB::quote(SJB_Request::getVar('custom_script_users', '', SJB_Request::METHOD_POST)); $defaultValue = SJB_Request::getVar('default_value', false); $defaultValueUser = SJB_Request::getVar('user_default_value', false); $selectedProduct = SJB_Request::getVar('postUnderProduct'); $importType = SJB_Request::getVar('import_type', 'increment'); if ($defaultValue) { foreach ($defaultValue as $key => $val) { $defaultValue[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8'); } } if ($defaultValueUser) { foreach ($defaultValueUser as $key => $val) { $defaultValueUser[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8'); } } $original_xml = !empty($_POST['xml']) ? SJB_DB::quote($_POST['xml']) : ''; $id = isset($_GET['id']) ? intval($_GET['id']) : 0; $addQuery = ''; $username = SJB_XmlImport::decodeSpecialEntities(SJB_Request::getVar('username', '')); $external_id = str_replace('_dog_', '@', SJB_Request::getVar('external_id', '')); $site_url = SJB_System::getSystemSettings("SITE_URL"); if ($addNewUser == 1 && empty($_REQUEST['mapped_user'])) { $error = 'Required user profile fields are not mapped'; SJB_HelperFunctions::redirect($site_url . '/edit-import/?id=' . $id . '&save_error=' . base64_encode($error)); } if (!empty($_REQUEST['mapped']) && is_array($_REQUEST['mapped']) && !empty($original_xml) && empty($errors)) { // make map $map1 = array(); $map2 = array(); $serUserMap = ''; foreach ($_REQUEST['mapped'] as $one) { $tmp = explode(':', $one); $map1[] = $tmp[0]; $map2[] = $tmp[1]; } if ($addNewUser == 1 && !empty($_REQUEST['mapped_user']) && is_array($_REQUEST['mapped_user'])) { // make map $mapUser1 = array(); $mapUser2 = array(); foreach ($_REQUEST['mapped_user'] as $one) { $tmp = explode(':', $one); $mapUser1[] = str_replace('user_', '', $tmp[0]); $mapUser2[] = $tmp[1]; } foreach ($mapUser1 as $key => $val) { $val = SJB_XmlImport::decodeSpecialEntities($val); $mapUser[$val] = $mapUser2[$key]; } $serUserMap = serialize($mapUser); } //$map = array_combine($map1, $map2); // PHP5 foreach ($map1 as $key => $val) { $val = SJB_XmlImport::decodeSpecialEntities($val); $map[$val] = $map2[$key]; } if ($selectedLogoOption && $selectedLogoOption != 'not_logo') { //get real data without any cache if (!SJB_ListingFieldDBManager::getListingFieldInfoByID('ListingLogo')) { $listing_field_info = array('id' => 'ListingLogo', 'type' => 'logo', 'is_system' => false, 'is_required' => false, 'caption' => 'Listing Logo'); $listing_field = new SJB_ListingField($listing_field_info, $type_id); $pages = SJB_PostingPagesManager::getFirstPageEachListingType(); SJB_ListingFieldManager::saveListingField($listing_field, $pages); } if ($key = array_search('ListingLogo', $map) !== false) { unset($map[$key]); } } if ($defaultValue) { foreach ($defaultValue as $key => $val) { if ($val == '') { unset($defaultValue[$key]); } } $defaultValue = SJB_db::quote(serialize($defaultValue)); $addQuery .= ", default_value = '" . $defaultValue . "'"; } if ($defaultValueUser) { foreach ($defaultValueUser as $keyuser => $valuser) { if ($valuser == '') { unset($defaultValueUser[$keyuser]); } } $defaultValueUser = SJB_db::quote(serialize($defaultValueUser)); $addQuery .= ", default_value_user = '******'"; } $queryParsUrl = SJB_DB::quote($pars_url); $queryImportType = SJB_DB::quote($importType); $queryId = intval($id); $query = "SET\n\t\t\t\t\t\t\t`custom_script_users` = ?s,\n\t\t\t\t\t\t\t`custom_script` = ?s,\n\t\t\t\t\t\t\t`type_id` = ?n,\n\t\t\t\t\t\t\t`name` = ?s,\n\t\t\t\t\t\t\t`description` = ?s,\n\t\t\t\t\t\t\t`url` = ?s,\n\t\t\t\t\t\t\t`usr_id` = ?n,\n\t\t\t\t\t\t\t`usr_name` = ?s,\n\t\t\t\t\t\t\t`maper_user` = ?s,\n\t\t\t\t\t\t\t`xml` = ?s,\n\t\t\t\t\t\t\t`add_new_user` = ?n,\n\t\t\t\t\t\t\t`username` = ?s,\n\t\t\t\t\t\t\t`external_id` = ?s,\n\t\t\t\t\t\t\t`product_sid` = ?n,\n\t\t\t\t\t\t\t`import_type` = ?s\n\t\t\t\t\t\t\t{$addQuery}"; if ($id > 0) { SJB_DB::query("UPDATE `parsers` {$query} WHERE id = ?n", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType, $queryId); } else { $id = SJB_DB::query("INSERT INTO `parsers` {$query}", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType); } $errorFile = ''; $xml_logo = null; switch ($selectedLogoOption) { case 'import_logo': $map[$selectedLogoField] = 'ListingLogo'; break; case 'upload_logo': if (!empty($_FILES['upload_logo_file'])) { if ($_FILES['upload_logo_file']['error']) { $errorFile = SJB_UploadFileManager::getErrorId($_FILES['upload_logo_file']['error']); } else { $width = SJB_Settings::getSettingByName('listing_picture_width'); $height = SJB_Settings::getSettingByName('listing_picture_height'); $property_info['second_width'] = SJB_Settings::getSettingByName('listing_thumbnail_width'); $property_info['second_height'] = SJB_Settings::getSettingByName('listing_thumbnail_height'); $picture = new SJB_UploadPictureManager(); $picture->setWidth($width); $picture->setHeight($height); if ($picture->isValidUploadedPictureFile('upload_logo_file')) { $xml_logo = "XMLImportLogo_{$id}"; $picture->setUploadedFileID($xml_logo); $picture->uploadPicture('upload_logo_file', $property_info); } } } break; } $logo_options = serialize(array('option' => $selectedLogoOption, 'field' => $selectedLogoField)); $serMap = serialize($map); if ($xml_logo) { SJB_DB::query("UPDATE `parsers` SET maper = ?s, `xml_logo` = ?s, logo_options = ?s WHERE id = ?n", $serMap, $xml_logo, $logo_options, $id); } else { SJB_DB::query("UPDATE `parsers` SET maper = ?s, logo_options = ?s WHERE id = ?n", $serMap, $logo_options, $id); } $form_submitted = SJB_Request::getVar('form_action'); if ($form_submitted == 'save_info') { SJB_HelperFunctions::redirect($site_url . '/show-import/'); } elseif ($form_submitted == 'apply_info') { $getterParameters = '?id=' . $id; if ($errorFile) { $getterParameters .= '&error=' . $errorFile; } SJB_HelperFunctions::redirect($site_url . '/edit-import/' . $getterParameters); } } else { if (empty($errors)) { $errors[] = 'No data to save'; } $tp->assign('errors', $errors); $tp->assign('xml', htmlspecialchars($original_xml)); $tp->assign('xmlToUser', $original_xml); $tp->assign('form_name', $parsing_name); $tp->assign('form_user', $usr_name); $tp->assign('form_url', $pars_url); $tp->assign('form_description', $form_description); $tp->display('add_step_three.tpl'); } break; } }
/** * Saves given xml object (formatted) * @param simplexml $oXml * @return string xml formatted string (ready to be saved to file) */ public static function saveXml($oXml) { $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($oXml->asXML()); return $dom->saveXML(); }