How to use match_Language method of Parser class

Best Cucumber Common Library code snippet using Parser.match_Language

mod_parser.php

Source:mod_parser.php Github

copy

Full Screen

1<?php2/**3*4* @package automod5* @version $Id$6* @copyright (c) 2008 phpBB Group7* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License8*9*/10/**11*/12if (!defined('IN_PHPBB'))13{14 exit;15}16/**17* MOD Parser class18* Basic wrapper to run individual parser functions19* Also contains some parsing functions that are global (i.e. needed for all parsers)20* @package automod21*22* Each parser requires the following functions:23* ~ set_file($path_to_mod_file)24* ~ a means of setting the data to be acted upon25* ~ get_details()26* ~ returns an array of information about the MOD27* ~ get_actions()28* ~ returns an array of the MODs actions29* ~ get_modx_version30* ~ returns the MODX version of the MOD being looked at31*32*/33class parser34{35 var $parser;36 /**37 * constructor, sets type of parser38 */39 function parser($ext)40 {41 switch ($ext)42 {43 case 'xml':44 // fix ticket 62689 only enter parser if it is xml45 //http://www.phpbb.com/bugs/modteamtools/6268946 $this->parser = new parser_xml();47 break;48 default:49 }50 }51 function set_file($file)52 {53 $this->parser->set_file($file);54 }55 function get_details()56 {57 return $this->parser->get_details();58 }59 function get_actions()60 {61 return $this->parser->get_actions();62 }63 function get_modx_version()64 {65 if (!$this->parser->modx_version)66 {67 $this->get_details();68 }69 return $this->parser->modx_version;70 }71 /**72 * Returns the needed sql query to reverse the actions taken by the given query73 * @todo: Add more74 */75 function reverse_query($orig_query)76 {77 if (preg_match('#ALTER TABLE\s([a-z_]+)\sADD(COLUMN|)\s([a-z_]+)#i', $orig_query, $matches))78 {79 return "ALTER TABLE {$matches[1]} DROP COLUMN {$matches[3]};";80 }81 else if (preg_match('#CREATE TABLE\s([a-z_])+#i', $orig_query, $matches))82 {83 return "DROP TABLE {$matches[1]};";84 }85 return false;86 }87 /**88 * Parse sql89 *90 * @param array $sql_query91 */92 function parse_sql(&$sql_query)93 {94 global $dbms, $table_prefix;95 if (!function_exists('get_available_dbms'))96 {97 global $phpbb_root_path, $phpEx;98 include($phpbb_root_path . 'includes/functions_install.' . $phpEx);99 }100 static $available_dbms;101 if (!isset($available_dbms))102 {103 $available_dbms = get_available_dbms($dbms);104 }105 $remove_remarks = $available_dbms[$dbms]['COMMENTS'];106 $delimiter = $available_dbms[$dbms]['DELIM'];107 if (sizeof($sql_query) == 1)108 {109 // do some splitting here110 $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);111 $remove_remarks($sql_query[0]);112 $sql_query = split_sql_file($sql_query[0], $delimiter);113 }114 else115 {116 $query_count = sizeof($sql_query);117 for ($i = 0; $i < $query_count; $i++)118 {119 $sql_query[$i] = preg_replace('#phpbb_#i', $table_prefix, $sql_query[$i]);120 $remove_remarks($sql_query[$i]);121 }122 }123 //return $sql_query;124 }125 /**126 * Returns the edits array, but now filled with edits to reverse the given array127 * @todo: Add more128 */129 function reverse_edits($actions)130 {131 $reverse_edits = array();132 foreach ($actions['EDITS'] as $file => $edit_ary)133 {134 foreach ($edit_ary as $edit_id => $edit)135 {136 foreach ($edit as $find => $action_ary)137 {138 foreach ($action_ary as $type => $command)139 {140 // it is possible for a single edit in the install process141 // to become more than one in the uninstall process142 while (isset($reverse_edits['EDITS'][$file][$edit_id]))143 {144 $edit_id++;145 }146 switch (strtoupper($type))147 {148 // for before and after adds, we use the find as a tool for more precise finds149 // this isn't perfect, but it seems better than having150 // finds of only a couple characters, like "/*"151 case 'AFTER ADD':152 $total_find = rtrim($find, "\n") . "\n" . trim($command, "\n");153 $reverse_edits['EDITS'][$file][$edit_id][$total_find]['replace with'] = $find;154 break;155 case 'BEFORE ADD':156 $total_find = rtrim($command, "\n") . "\n" . trim($find, "\n");157 // replace with the find158 $reverse_edits['EDITS'][$file][$edit_id][$total_find]['replace with'] = $find;159 break;160 case 'REPLACE WITH':161 case 'REPLACE, WITH':162 case 'REPLACE-WITH':163 case 'REPLACE':164 // replace $command (new code) with $find (original code)165 $reverse_edits['EDITS'][$file][$edit_id][$command]['replace with'] = $find;166 break;167 case 'IN-LINE-EDIT':168 // build the reverse just like the normal action169 foreach ($command as $action_id => $inline_edit)170 {171 foreach ($inline_edit as $inline_find => $inline_action_ary)172 {173 foreach ($inline_action_ary as $inline_action => $inline_command)174 {175 $inline_command = $inline_command[0];176 177 switch (strtoupper($inline_action))178 {179 case 'IN-LINE-AFTER-ADD':180 case 'IN-LINE-BEFORE-ADD':181 // Replace with a blank string182 $reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command]['in-line-replace'][] = '';183 break;184 185 case 'IN-LINE-REPLACE':186 // replace with the inline find187 $reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command][$inline_action][] = $inline_find;188 break;189 190 default:191 // For the moment, we do nothing. What about increment?192 break;193 }194 195 $action_id++;196 }197 }198 }199 break;200 default:201 // again, increment202 break;203 }204 }205 }206 }207 }208 if (!empty($actions['NEW_FILES']))209 {210 foreach ($actions['NEW_FILES'] as $source => $target)211 {212 $reverse_edits['DELETE_FILES'][$source] = $target;213 }214 }215 if (empty($actions['SQL']))216 {217 return $reverse_edits;218 }219 if (sizeof($actions['SQL']) == 1)220 {221 $actions['SQL'] = explode("\n", $actions['SQL'][0]);222 }223 foreach ($actions['SQL'] as $query)224 {225 $reverse_edits['SQL'][] = parser::reverse_query($query);226 }227 return $reverse_edits;228 }229}230/**231* XML parser232* @package automod233*/234class parser_xml235{236 var $data;237 var $file;238 var $modx_version;239 /**240 * set data to read from241 */242 function set_file($file)243 {244 // Shouldn't ever happen since the master class reads file names from245 // the file system and lists them246 if (!file_exists($file))247 {248 trigger_error('Cannot locate File: ' . $file);249 }250 $this->file = $file;251 $this->data = trim(@file_get_contents($file));252 $this->data = str_replace(array("\r\n", "\r"), "\n", $this->data);253 $XML = new xml_array();254 $this->data = $XML->parse($this->file, $this->data);255 return;256 }257 /**258 * return array of the basic MOD details259 */260 function get_details()261 {262 global $user;263 if (empty($this->data))264 {265 $this->set_file($this->file);266 }267 $header = array(268 'MOD-VERSION' => array(0 => array('children' => array())),269 'INSTALLATION' => array(0 => array('children' => array('TARGET-VERSION' => array(0 => array('data' => ''))))),270 'AUTHOR-GROUP' => array(0 => array('children' => array('AUTHOR' => array()))),271 'HISTORY' => array(0 => array('children' => array('ENTRY' => array()))),272 );273 $version = $phpbb_version = '';274 $header = $this->data[0]['children']['HEADER'][0]['children'];275 // get MOD version information276 // This is also our first opportunity to differentiate MODX 1.0.x from277 // MODX 1.2.0.278 if (isset($header['MOD-VERSION'][0]['children']))279 {280 $this->modx_version = 1.0;281 $version_info = $header['MOD-VERSION'][0]['children'];282 $version = (isset($version_info['MAJOR'][0]['data'])) ? trim($version_info['MAJOR'][0]['data']) : 0;283 $version .= '.' . ((isset($version_info['MINOR'][0]['data'])) ? trim($version_info['MINOR'][0]['data']) : 0);284 $version .= '.' . ((isset($version_info['REVISION'][0]['data'])) ? trim($version_info['REVISION'][0]['data']) : 0);285 $version .= (isset($version_info['RELEASE'][0]['data'])) ? trim($version_info['RELEASE'][0]['data']) : '';286 }287 else288 {289 $this->modx_version = 1.2;290 $version = trim($header['MOD-VERSION'][0]['data']);291 }292 // get phpBB version recommendation293 switch ($this->modx_version)294 {295 case 1.0:296 if (isset($header['INSTALLATION'][0]['children']['TARGET-VERSION'][0]['children']))297 {298 $version_info = $header['INSTALLATION'][0]['children']['TARGET-VERSION'][0]['children'];299 $phpbb_version = (isset($version_info['MAJOR'][0]['data'])) ? trim($version_info['MAJOR'][0]['data']) : 0;300 $phpbb_version .= '.' . ((isset($version_info['MINOR'][0]['data'])) ? trim($version_info['MINOR'][0]['data']) : 0);301 $phpbb_version .= '.' . ((isset($version_info['REVISION'][0]['data'])) ? trim($version_info['REVISION'][0]['data']) : 0);302 $phpbb_version .= (isset($version_info['RELEASE'][0]['data'])) ? trim($version_info['RELEASE'][0]['data']) : '';303 }304 break;305 case 1.2:306 default:307 $phpbb_version = (isset($header['INSTALLATION'][0]['children']['TARGET-VERSION'][0]['data'])) ? $header['INSTALLATION'][0]['children']['TARGET-VERSION'][0]['data'] : 0;308 break;309 }310 $author_info = $header['AUTHOR-GROUP'][0]['children']['AUTHOR'];311 $author_details = array();312 for ($i = 0; $i < sizeof($author_info); $i++)313 {314 $author_details[] = array(315 'AUTHOR_NAME' => isset($author_info[$i]['children']['USERNAME'][0]['data']) ? trim($author_info[$i]['children']['USERNAME'][0]['data']) : '',316 'AUTHOR_EMAIL' => isset($author_info[$i]['children']['EMAIL'][0]['data']) ? trim($author_info[$i]['children']['EMAIL'][0]['data']) : '',317 'AUTHOR_REALNAME' => isset($author_info[$i]['children']['REALNAME'][0]['data']) ? trim($author_info[$i]['children']['REALNAME'][0]['data']) : '',318 'AUTHOR_WEBSITE' => isset($author_info[$i]['children']['HOMEPAGE'][0]['data']) ? trim($author_info[$i]['children']['HOMEPAGE'][0]['data']) : '',319 );320 }321 // history322 $history_info = (!empty($header['HISTORY'][0]['children']['ENTRY'])) ? $header['HISTORY'][0]['children']['ENTRY'] : array();323 $history_size = sizeof($history_info);324 $mod_history = array();325 for ($i = 0; $i < $history_size; $i++)326 {327 $changes = array();328 $entry = $history_info[$i]['children'];329 $changelog = isset($entry['CHANGELOG']) ? $entry['CHANGELOG'] : array();330 $changelog_size = sizeof($changelog);331 $changelog_id = 0;332 for ($j = 0; $j < $changelog_size; $j++)333 {334 // Ignore changelogs in foreign languages except in the case that there is no335 // match for the current user's language336 // TODO: Look at modifying localise_tags() for use here.337 if (match_language($user->data['user_lang'], $changelog[$j]['attrs']['LANG']))338 {339 $changelog_id = $j;340 }341 }342 $change_count = isset($changelog[$changelog_id]['children']['CHANGE']) ? sizeof($changelog[$changelog_id]['children']['CHANGE']) : 0;343 for ($j = 0; $j < $change_count; $j++)344 {345 $changes[] = $changelog[$changelog_id]['children']['CHANGE'][$j]['data'];346 }347 switch ($this->modx_version)348 {349 case 1.0:350 $changelog_version_ary = (isset($entry['REV-VERSION'][0]['children'])) ? $entry['REV-VERSION'][0]['children'] : array();351 $changelog_version = (isset($changelog_version_ary['MAJOR'][0]['data'])) ? trim($changelog_version_ary['MAJOR'][0]['data']) : 0;352 $changelog_version .= '.' . ((isset($changelog_version_ary['MINOR'][0]['data'])) ? trim($changelog_version_ary['MINOR'][0]['data']) : 0);353 $changelog_version .= '.' . ((isset($changelog_version_ary['REVISION'][0]['data'])) ? trim($changelog_version_ary['REVISION'][0]['data']) : 0);354 $changelog_version .= (isset($changelog_version_ary['RELEASE'][0]['data'])) ? trim($changelog_version_ary['RELEASE'][0]['data']) : '';355 break;356 case 1.2:357 default:358 $changelog_version = (isset($entry['REV-VERSION'][0]['data'])) ? $entry['REV-VERSION'][0]['data'] : '0.0.0';359 break;360 }361 $mod_history[] = array(362 'DATE' => $entry['DATE'][0]['data'],363 'VERSION' => $changelog_version,364 'CHANGES' => $changes,365 );366 }367 $children = array();368 // Parse links369 if ($this->modx_version == 1.2)370 {371 $link_group = (isset($header['LINK-GROUP'][0]['children'])) ? $header['LINK-GROUP'][0]['children'] : array();372 if (isset($link_group['LINK']))373 {374 for ($i = 0, $size = sizeof($link_group['LINK']); $i <= $size; $i++)375 {376 // do some stuff with attrs377 // commented out due to a possible PHP bug. When using this,378 // sizeof($link_group) changed each time ...379 // $attrs = &$link_group[$i]['attrs'];380 if (!isset($link_group['LINK'][$i]))381 {382 continue;383 }384 if ($link_group['LINK'][$i]['attrs']['TYPE'] == 'text')385 {386 continue;387 }388 $children[$link_group['LINK'][$i]['attrs']['TYPE']][] = array(389 'href' => $link_group['LINK'][$i]['attrs']['HREF'],390 'realname' => isset($link_group['LINK'][$i]['attrs']['REALNAME']) ? $link_group['LINK'][$i]['attrs']['REALNAME'] : core_basename($link_group['LINK'][$i]['attrs']['HREF']),391 'title' => localise_tags($link_group, 'LINK', $i),392 'lang' => $link_group['LINK'][$i]['attrs']['LANG'],393 );394 }395 }396 }397 // try not to hardcode schema?398 $details = array(399 'MOD_PATH' => $this->file,400 'MOD_NAME' => localise_tags($header, 'TITLE'),401 'MOD_DESCRIPTION' => nl2br(localise_tags($header, 'DESCRIPTION')),402 'MOD_VERSION' => htmlspecialchars(trim($version)),403// 'MOD_DEPENDENCIES' => (isset($header['TITLE'][0]['data'])) ? htmlspecialchars(trim($header['TITLE'][0]['data'])) : '',404 'AUTHOR_DETAILS' => $author_details,405 'AUTHOR_NOTES' => nl2br(localise_tags($header, 'AUTHOR-NOTES')),406 'MOD_HISTORY' => $mod_history,407 'PHPBB_VERSION' => $phpbb_version,408 'CHILDREN' => $children,409 );410 return $details;411 }412 /**413 * returns complex array containing all mod actions414 */415 function get_actions()416 {417 global $db, $user;418 $actions = array();419 $xml_actions = $this->data[0]['children']['ACTION-GROUP'][0]['children'];420 // sql421 $actions['SQL'] = array();422 $sql_info = (!empty($xml_actions['SQL'])) ? $xml_actions['SQL'] : array();423 $match_dbms = array();424 switch ($db->sql_layer)425 {426 case 'firebird':427 case 'oracle':428 case 'postgres':429 case 'sqlite':430 case 'mssql':431 case 'db2':432 $match_dbms = array($db->sql_layer);433 break;434 case 'mssql_odbc':435 $match_dbms = array('mssql');436 break;437 // and now for the MySQL fun438 // This will generate an array of things we can probably use, but439 // will not have any priority440 case 'mysqli':441 $match_dbms = array('mysql_41', 'mysqli', 'mysql');442 break;443 case 'mysql4':444 case 'mysql':445 if (version_compare($db->sql_server_info(true), '4.1.3', '>='))446 {447 $match_dbms = array('mysql_41', 'mysql4', 'mysql', 'mysqli');448 }449 else if (version_compare($db->sql_server_info(true), '4.0.0', '>='))450 {451 $match_dbms = array('mysql_40', 'mysql4', 'mysql', 'mysqli');452 }453 else454 {455 $match_dbms = array('mysql');456 }457 break;458 // Should never happen459 default:460 break;461 }462 for ($i = 0; $i < sizeof($sql_info); $i++)463 {464 if ($this->modx_version == 1.0)465 {466 $actions['SQL'][] = (!empty($sql_info[$i]['data'])) ? trim($sql_info[$i]['data']) : '';467 }468 else if ($this->modx_version == 1.2)469 {470 // Make a slightly shorter name.471 $xml_dbms = &$sql_info[$i]['attrs']['DBMS'];472 if (!isset($sql_info[$i]['attrs']['DBMS']) || in_array($xml_dbms, $match_dbms))473 {474 $actions['SQL'][] = (!empty($sql_info[$i]['data'])) ? trim($sql_info[$i]['data']) : '';475 }476 else477 {478 // NOTE: skipped SQL is not currently useful479 $sql_skipped = true;480 }481 }482 }483 // new files484 $new_files_info = (!empty($xml_actions['COPY'])) ? $xml_actions['COPY'] : array();485 for ($i = 0; $i < sizeof($new_files_info); $i++)486 {487 $new_files = $new_files_info[$i]['children']['FILE'];488 for ($j = 0; $j < sizeof($new_files); $j++)489 {490 $from = str_replace('\\', '/', $new_files[$j]['attrs']['FROM']);491 $to = str_replace('\\', '/', $new_files[$j]['attrs']['TO']);492 $actions['NEW_FILES'][$from] = $to;493 }494 }495 $delete_files_info = (!empty($xml_actions['DELETE'])) ? $xml_actions['DELETE'] : array();496 for ($i = 0; $i < sizeof($delete_files_info); $i++)497 {498 $delete_files = $delete_files_info[$i]['children']['FILE'];499 for ($j = 0; $j < sizeof($delete_files); $j++)500 {501 $name = str_replace('\\', '/', $delete_files[$j]['attrs']['NAME']);502 $actions['DELETE_FILES'][] = $name;503 }504 }505 // open506 $open_info = (!empty($xml_actions['OPEN'])) ? $xml_actions['OPEN'] : array();507 for ($i = 0; $i < sizeof($open_info); $i++)508 {509 $current_file = str_replace('\\', '/', trim($open_info[$i]['attrs']['SRC']));510 $actions['EDITS'][$current_file] = array();511 $edit_info = (!empty($open_info[$i]['children']['EDIT'])) ? $open_info[$i]['children']['EDIT'] : array();512 // find, after add, before add, replace with513 for ($j = 0; $j < sizeof($edit_info); $j++)514 {515 $action_info = (!empty($edit_info[$j]['children'])) ? $edit_info[$j]['children'] : array();516 // store some array information to help decide what kind of operation we're doing517 $action_count = $total_action_count = $remove_count = $find_count = 0;518 if (isset($action_info['ACTION']))519 {520 $action_count += sizeof($action_info['ACTION']);521 }522 if (isset($action_info['INLINE-EDIT']))523 {524 $total_action_count += sizeof($action_info['INLINE-EDIT']);525 }526 if (isset($action_info['REMOVE']))527 {528 $remove_count = sizeof($action_info['REMOVE']); // should be an integer bounded between zero and one529 }530 if (isset($action_info['FIND']))531 {532 $find_count = sizeof($action_info['FIND']);533 }534 // the basic idea is to transform a "remove" tag into a replace-with action535 if ($remove_count && !$find_count)536 {537 // but we still support it if $remove_count is > 1538 for ($k = 0; $k < $remove_count; $k++)539 {540 // if there is no find tag associated, handle it directly541 $actions['EDITS'][$current_file][$j][trim($action_info['REMOVE'][$k]['data'], "\n\r")]['replace with'] = '';542 }543 }544 else if ($remove_count && $find_count)545 {546 // if there is a find and a remove, transform into a replace-with547 // action, and let the logic below sort out the relationships.548 for ($k = 0; $k < $remove_count; $k++)549 {550 $insert_index = (isset($action_info['ACTION'])) ? sizeof($action_info['ACTION']) : 0;551 $action_info['ACTION'][$insert_index] = array(552 'data' => '',553 'attrs' => array('TYPE' => 'replace with'),554 );555 }556 }557 else if (!$find_count)558 {559 trigger_error(sprintf($user->lang['INVALID_MOD_NO_FIND'], htmlspecialchars($action_info['ACTION'][0]['data'])), E_USER_WARNING);560 }561 // first we try all the possibilities for a FIND/ACTION combo, then look at inline possibilities.562 if (isset($action_info['ACTION']))563 {564 for ($k = 0; $k < $find_count; $k++)565 {566 // is this anything but the last iteration of the loop?567 if ($k < ($find_count - 1))568 {569 // NULL has special meaning for an action ... no action to be taken; advance pointer570 $actions['EDITS'][$current_file][$j][$action_info['FIND'][$k]['data']] = NULL;571 }572 else573 {574 // this is the last iteration, assign the action tags575 for ($l = 0; $l < $action_count; $l++)576 {577 $type = str_replace('-', ' ', $action_info['ACTION'][$l]['attrs']['TYPE']);578 $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$k]['data'], "\n\r")][$type] = (isset($action_info['ACTION'][$l]['data'])) ? preg_replace("#^(\s)+\n#", '', rtrim(trim($action_info['ACTION'][$l]['data'], "\n"))) : '';579 }580 }581 }582 }583 else584 {585 if (!$remove_count && !$total_action_count)586 {587 trigger_error(sprintf($user->lang['INVALID_MOD_NO_ACTION'], htmlspecialchars($action_info['FIND'][0]['data'])), E_USER_WARNING);588 }589 }590 // add comment to the actions array591 $actions['EDITS'][$current_file][$j]['comment'] = localise_tags($action_info, 'COMMENT');592 // inline593 if (isset($action_info['INLINE-EDIT']))594 {595 $inline_info = (!empty($action_info['INLINE-EDIT'])) ? $action_info['INLINE-EDIT'] : array();596 if (isset($inline_info[0]['children']['INLINE-REMOVE']) && sizeof($inline_info[0]['children']['INLINE-REMOVE']))597 {598 // overwrite the existing array with the new one599 $inline_info[0]['children'] = array(600 'INLINE-FIND' => $inline_info[0]['children']['INLINE-REMOVE'],601 'INLINE-ACTION' => array(602 0 => array(603 'attrs' => array('TYPE' => 'replace-with'),604 'data' => '',605 ),606 ),607 );608 }609 if ($find_count > $total_action_count)610 {611 // Yeah, $k is used more than once for different information612 for ($k = 0; $k < $find_count; $k++)613 {614 // is this anything but the last iteration of the loop?615 if ($k < ($find_count - 1))616 {617 // NULL has special meaning for an action ... no action to be taken; advance pointer618 $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$k]['data'], "\r\n")] = NULL;619 }620 }621 }622 /*623 * This loop attaches the in-line information to the _last624 * find_ in the <edit> tag. This is the intended behavior625 * Any additional finds ought to be in a different edit tag626 */627 for ($k = 0; $k < sizeof($inline_info); $k++)628 {629 $inline_data = (!empty($inline_info[$k]['children'])) ? $inline_info[$k]['children'] : array();630 $inline_find_count = (isset($inline_data['INLINE-FIND'])) ? sizeof($inline_data['INLINE-FIND']) : 0;631 $inline_comment = localise_tags($inline_data, 'INLINE-COMMENT');632 $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$find_count - 1]['data'], "\r\n")]['in-line-edit']['inline-comment'] = $inline_comment;633 $inline_actions = (!empty($inline_data['INLINE-ACTION'])) ? $inline_data['INLINE-ACTION'] : array();634 if (empty($inline_actions))635 {636 trigger_error(sprintf($user->lang['INVALID_MOD_NO_ACTION'], htmlspecialchars($inline_data['INLINE-FIND'][0]['data'])), E_USER_WARNING);637 }638 if (empty($inline_find_count))639 {640 trigger_error(sprintf($user->lang['INVALID_MOD_NO_FIND'], htmlspecialchars($inline_actions[0]['data'])), E_USER_WARNING);641 }642 for ($l = 0; $l < $inline_find_count; $l++)643 {644 $inline_find = $inline_data['INLINE-FIND'][$l]['data'];645 // trying to reduce the levels of arrays without impairing features.646 // need to keep the "full" edit intact.647 //648 // inline actions must be trimmed in case the MOD author649 // inserts a new line by mistake650 if ($l < ($inline_find_count - 1))651 {652 $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$find_count - 1]['data'], "\r\n")]['in-line-edit'][$k][$inline_find]['in-line-'][] = null;653 }654 else655 {656 for ($m = 0; $m < sizeof($inline_actions); $m++)657 {658 $type = str_replace(',', '-', str_replace(' ', '', $inline_actions[$m]['attrs']['TYPE']));659 if (!empty($inline_actions[$m]['data']))660 {661 $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$find_count - 1]['data'], "\r\n")]['in-line-edit'][$k][$inline_find]['in-line-' . $type][] = trim($inline_actions[$m]['data'], "\n");662 }663 else664 {665 $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$find_count - 1]['data'], "\r\n")]['in-line-edit'][$k][$inline_find]['in-line-' . $type][] = '';666 }667 }668 }669 }670 }671 }672 }673 }674 if (!empty($xml_actions['PHP-INSTALLER']))675 {676 $actions['PHP_INSTALLER'] = $xml_actions['PHP-INSTALLER'][0]['data'];677 }678 if (!empty($xml_actions['DIY-INSTRUCTIONS']))679 {680 $actions['DIY_INSTRUCTIONS'] = localise_tags($xml_actions, 'DIY-INSTRUCTIONS');681 }682 return $actions;683 }684}685/**686* XML processing687* @package automod688*/689class xml_array690{691 var $output = array();692 var $parser;693 var $XML;694 function parse($file, $XML)695 {696 $this->parser = xml_parser_create();697 xml_set_object($this->parser, $this);698 xml_set_element_handler($this->parser, "tag_open", "tag_closed");699 xml_set_character_data_handler($this->parser, "tag_data");700 $this->XML = xml_parse($this->parser, $XML);701 if (!$this->XML)702 {703 die(sprintf("<strong>XML error</strong>: %s at line %d. View the file %s in a web browser for a more detailed error message.",704 xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser), $file));705 }706 xml_parser_free($this->parser);707 return $this->output;708 }709 function tag_open($parser, $name, $attrs)710 {711 $tag = array("name" => $name, "attrs" => $attrs);712 array_push($this->output, $tag);713 }714 function tag_data($parser, $tag_data)715 {716 // Should be a string but' let's make sure.717 $tag_data = (string) $tag_data;718 if ($tag_data !== '')719 {720 if (isset($this->output[sizeof($this->output) - 1]['data']))721 {722 $this->output[sizeof($this->output) - 1]['data'] .= $tag_data;723 }724 else725 {726 $this->output[sizeof($this->output) - 1]['data'] = $tag_data;727 }728 }729 }730 function tag_closed($parser, $name)731 {732 $this->output[sizeof($this->output) - 2]['children'][$name][] = $this->output[sizeof($this->output) - 1];733 array_pop($this->output);734 }735}736?>...

Full Screen

Full Screen

parse_nfo.php

Source:parse_nfo.php Github

copy

Full Screen

1<?php2/*3 * This file is part of Urd.4 * vim:ts=4:expandtab:cindent5 *6 * Urd is free software; you can redistribute it and/or modify7 * it under the terms of the GNU General Public License as published by8 * the Free Software Foundation; either version 3 of the License, or9 * (at your option) any later version.10 * Urd is distributed in the hope that it will be useful,11 * but WITHOUT ANY WARRANTY; without even the implied warranty of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU General Public License for more details.14 *15 * You should have received a copy of the GNU General Public License16 * along with this program. See the file "COPYING". If it does not17 * exist, see <http://www.gnu.org/licenses/>.18 *19 * $LastChangedDate: 2014-05-29 01:03:02 +0200 (do, 29 mei 2014) $20 * $Rev: 3058 $21 * $Author: gavinspearhead@gmail.com $22 * $Id: parse_nfo.php 3058 2014-05-28 23:03:02Z gavinspearhead@gmail.com $23 */24if (!defined('ORIGINAL_PAGE')) {25 die('This file cannot be accessed directly.');26}27class nfo_parser28{29 private static function match_iafd_link($line)30 {31 $rv = preg_match('/(http\:\/\/.*iafd\.com\/[\w?\-\/?+%-=]*)/i', $line, $matches);32 if ($rv) {33 return trim($matches[1]);34 } else {35 return FALSE;36 }37 }38 private static function match_imdb_link($line)39 {40 $rv = preg_match('/(http\:\/\/.*imdb\.(com|de|es|pt|fr|it)\/[\w?\-\/?]*)/i', $line, $matches);41 if ($rv) {42 return trim($matches[1]);43 } else {44 return FALSE;45 }46 }47 private static function match_tvrage_link($line)48 {49 $rv = preg_match('/(http\:\/\/.*\.tvrage\.com\/\w*)/i', $line, $matches);50 if ($rv) {51 return trim($matches[1]);52 } else {53 return FALSE;54 }55 }56 private static function match_tvcom_link($line)57 {58 $rv = preg_match('/(http\:\/\/.*\.tv\.com\/[\w.\/\-]*)/i', $line, $matches);59 if ($rv) {60 return trim($matches[1]);61 } else {62 return FALSE;63 }64 }65 private static function match_title($line)66 {67 $rv = preg_match('/(\btitle\b|file\s?name\b|\benglish name\b|\bname\b)[\s:\-.\[]*((([\w\s.:\'\-]+)[,|\/]*)+)/i', $line, $matches);68 if ($rv && isset($matches[2]) && !stristr($line, 'subtitle') && !stristr($line, 'imdb.com')) {69 $match = str_ireplace('.avi', '', $matches[2]);70 $match = str_ireplace('.mkv', '', $match);71 $match = str_ireplace('.', ' ', $match);72 return trim($match);73 } else {74 return FALSE;75 }76 }77 private static function match_serietitle($line)78 {79 $rv = preg_match('/(\bserie\b)[\s:\-.\[]*((([\w.:\']+)[\s,|\/]*)+)/i', $line, $matches);80 if ($rv && isset($matches[2])) {81 $match = str_ireplace('.avi', '', $matches[2]);82 return trim($match);83 } else {84 return FALSE;85 }86 }87 private static function match_duration($line)88 {89 $rv = preg_match('/(\bruntime\b|\bduration\b|\blaufzeit\b|\bdauer\b)[a-z:\s\-.\[]*((\d+[:.]\d+([:.]\d+)*)|((\d+\s*hr?s?\s*)?\d+\s*mi?n?\s*(\d+\s*se?c?)?))/i', $line, $matches);90 if ($rv && isset($matches[2])) {91 $match = trim($matches[2]);92 if ($match != '') {93 return trim($matches[2]);94 } else {95 return FALSE;96 }97 } else {98 return FALSE;99 }100 }101 private static function match_url($line)102 { // note the ?: means don't capture; ?| means collapse two option to one match103 $rv = preg_match('!(?:\borigin\b|\burl\b|\bwebsite\b|\bsite\b|\bsource\b)(?|.*(https?://[\w\d\-/]+\.[\w\d\-/.]+)|[\s:\-.\[]*((?:(?:[\w]+)[\s.:,|\-\/]*)+))!i', $line, $matches);104 if ($rv && isset($matches[1])) {105 $url = trim($matches[1]);106 if (strstr($url, ' ')) { //assume that URLs don't contain spaces107 return FALSE;108 }109 if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://') {110 $url = 'http://' . $url;111 }112 $host = @parse_url($url, PHP_URL_HOST);113 if (strpos($host, '.')) { // must at least contain one .114 $addr = gethostbyname($host);115 if ($addr !== FALSE) {116 return $url;117 } else {118 return FALSE;119 }120 } else {121 return FALSE;122 }123 } else {124 return FALSE;125 }126 }127 private static function match_subtitles($line)128 {129 $rv = preg_match('/(\bsubs\b|\bsubtitles\b)[\s:\-.\[]*((([\w]+)[\s,|\/]*)+)/i', $line, $matches);130 if ($rv && isset($matches[2]) && !stristr($matches[2], 'vobsub')) {131 return trim($matches[2]);132 } else {133 return FALSE;134 }135 }136 private static function match_rating($line)137 {138 $rv = preg_match('/(\bimdb[\s-]?rating\b|\bscore\b|\bimdb\b|\b\rating\b)[\s:\-.\[(]*(\d+(\.\d+)?)/i', $line, $matches);139 if ($rv && isset($matches[2])) {140 return round_rating($matches[2]);141 } else {142 return FALSE;143 }144 }145 private static function match_genre($line)146 {147 $rv = preg_match('/(\bgenre\b|\bcategory\b)[\s:\-.\[]*((([\w]+)[\s,|\/]*)+)/i', $line, $matches);148 if ($rv && isset($matches[2])) {149 return trim($matches[2]);150 } else {151 return FALSE;152 }153 }154 private static function match_language($line)155 {156 $rv = preg_match('/(\blanguage\b)[\s:\-.\[]*((([\w]+)[\s,|\/]*)+)/i', $line, $matches);157 if ($rv && isset($matches[2])) {158 return trim($matches[2]);159 } else {160 return FALSE;161 }162 }163 private static function match_year($line)164 {165 $rv = preg_match('/(\byear\b)[\s:\-.\[]*(\d{2,4})/i', $line, $matches);166 if ($rv && isset($matches[2]) && is_numeric($matches[2])) {167 return trim($matches[2]);168 } else {169 return FALSE;170 }171 }172 private static function match_albumtitle($line)173 {174 $rv = preg_match('/(\balbum\b|\btitle\b|\btitel\b)[\s:\-.\[]*((([\w]+)[\s,|\/()!<>]*)+)/i', $line, $matches);175 if ($rv && isset($matches[2])) {176 return trim($matches[2]);177 } else {178 return FALSE;179 }180 }181 private static function match_band($line)182 {183 $rv = preg_match('/(\bband\b|\bartists?\b)[\s:\-.\[]*((([\w]+)[\s,|\/!<>()]*)+)/i', $line, $matches);184 if ($rv && isset($matches[2])) {185 return trim($matches[2]);186 } else {187 return FALSE;188 }189 }190 private static function match_software_os($line)191 {192 $rv = preg_match('/(\bos type\b|\boperating systems?\b|\bos\b)[\s:\-.\[]*((([\w]+)[\s,|\/]*)+)/i', $line, $matches);193 if ($rv && isset( $matches[2])) {194 return trim($matches[2]);195 } else {196 return FALSE;197 }198 }199 private static function match_software_format($line)200 {201 $rv = preg_match('/(\bformat\b)[\s:\-.\[]*((([\w]+)[\s,|\/]*)+)/i', $line, $matches);202 if ($rv && isset($matches[2])) {203 return trim($matches[2]);204 } else {205 return FALSE;206 }207 }208 private static function match_software_genre($line)209 {210 $rv = preg_match('/(\bsoftware type\b|\bsoftware genre\b|\bsoftware category\b|\bgame type\b)[\s:\-.\[]*((([\w]+)[\s,|\/]*)+)/i', $line, $matches);211 if ($rv && isset($matches[2])) {212 if (stristr($matches[1], 'game')) {213 $matches[2] = 'Game: ' . $matches[2];214 }215 return trim($matches[2]);216 } else {217 return FALSE;218 }219 }220 private static function match_format($line)221 {222 $rv = preg_match('/(\bformat\b)[\s:\-.\[]*((([\w]+)[\s,|\/]*)+)/i', $line, $matches);223 if ($rv && isset($matches[2])) {224 return trim($matches[2]);225 } else {226 return FALSE;227 }228 }229 private static function match_softwaretitle($line)230 {231 $rv = preg_match('/(\bsoftware name\b|\btitle\b|\btitel\b|\bname\b)[\s:\-.\[]*((([\w]+)[\s,|\/]*)+)/i', $line, $matches);232 if ($rv && isset($matches[2])) {233 return trim($matches[2]);234 } else {235 return FALSE;236 }237 }238 private static function set_info(array &$file_nfo, $index, $value)239 {240 if ((!isset($file_nfo[$index]) || strlen($file_nfo[$index]) < 2) && strlen($value) > 2) {241 $file_nfo[$index] = trim($value);242 $pos = strpos($file_nfo[$index], ' ');243 if ($pos > 10) {244 $file_nfo[$index] = trim(substr($file_nfo[$index], 0, $pos));245 }246 }247 }248 private static function parse_tvcom_info($movie_link)249 {250 $f = @fopen($movie_link, 'r');251 if ($f === FALSE) {252 echo_debug('Cannot open link: ' . $movie_link, LOG_INFO);253 return FALSE;254 }255 $got_title = $got_rating = $got_year = FALSE;256 $rv = array('name'=>NULL, 'rating'=>NULL, 'year'=>NULL);257 while (($line = fgets($f)) !== FALSE) {258 if (!$got_title && preg_match('/<title>(.*)at TV.com<\/title>/i', $line, $matches)) {259 $name = html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8');260 str_replace('"', '', $name);261 $rv['name'] = utf8_decode($name);262 $got_title = TRUE;263 } elseif (!$got_rating && preg_match('/<span class="number">([0-9]{1,2})\.?(\d)?<\/span>/i', $line, $matches)) {264 $decimals = $matches[2];265 if ($decimals >= 3 && $decimals <= 7) {266 $decimals = 5;267 } else {268 $decimals = 0;269 }270 $rv['rating'] = $matches[1] . ".$decimals";271 $got_rating = TRUE;272 } elseif (!$got_year && preg_match('/<p>\w+day\s+\w+\s+\d+,\s+([0-9]{4})<\/p>/i', $line, $matches)) {273 $rv['year'] = $matches[1];274 $got_year = TRUE;275 } elseif (!$got_year && preg_match('/<div class="airdate">Aired:\s+\d+\/\d+\/(\d+)\s*<\/div>/i', $line, $matches)) {276 $year = $matches[1];277 $got_year = TRUE;278 if ($year < 30) {279 $year += 2000;280 } elseif ($year < 100) {281 $year += 1900;282 }283 $rv['year'] = $year;284 }285 if ($got_rating && $got_title && $got_year) {286 break;287 }288 }289 fclose($f);290 return $rv;291 }292 private static function parse_tvrage_info($movie_link)293 {294 $f = @fopen($movie_link, 'r');295 if ($f === FALSE) {296 return FALSE;297 }298 $got_title = $got_rating = FALSE;299 $rv = array ('name'=>NULL, 'rating'=>NULL);300 while (($line = fgets($f)) !== FALSE) {301 if (!$got_title && preg_match('/<h3[\w\s\'\"\=]*>(.*)\s\(\d+\s*Fans\).*<\/h3>/i', $line, $matches)) {302 $name = html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8');303 str_replace('"', '', $name);304 $rv['name'] = utf8_decode($name);305 $got_title = TRUE;306 } elseif (!$got_rating && preg_match('/(\d{1,2})\.(\d)\/10/i', $line, $matches)) {307 $decimals = $matches[2];308 if ($decimals >= 3 && $decimals <= 7) {309 $decimals = 5;310 } else {311 $decimals = 0;312 }313 $rv['rating'] = $matches[1]. ".$decimals";314 $got_rating = TRUE;315 }316 if ($got_rating && $got_title) {317 break;318 }319 }320 fclose($f);321 return $rv;322 }323 private static function parse_imdb_info($movie_link)324 {325 $f = @fopen($movie_link, 'r');326 if ($f === FALSE) {327 return FALSE;328 }329 $got_title = $got_rating = $got_genre = $next_is_genre = FALSE;330 $rv = array ('name'=>NULL, 'year'=>NULL, 'rating'=>NULL, 'genre'=>NULL);331 while (($line = fgets($f)) !== FALSE) {332 if (!$got_title && preg_match('/<title>(.*)\(.*(\d{4}).*\).*<\/title>/i', $line, $matches)) {333 $name = html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8');334 str_replace('"', '', $name);335 $rv['name'] = utf8_decode($name);336 $rv['year'] = $matches[2];337 $got_title = TRUE;338 } elseif (!$got_rating && preg_match('/>([0-9]{1,2})\.([0-9]).*\/10/i', $line, $matches)) {339 $decimals = (int) $matches[2];340 $value = (int) $matches[1];341 if ($decimals >= 3 && $decimals <= 7) {342 $decimals = 5;343 } else {344 if ($decimals > 7) {345 $value += 1;346 }347 $decimals = 0;348 }349 $rv['rating'] = "$value.$decimals";350 $got_rating = TRUE;351 } elseif (!$got_genre && preg_match('/Genres?:<\/h[54]>/iU', $line)) {352 $next_is_genre = 2;353 } elseif ($next_is_genre > 0 && !$got_genre) {354 $line = trim(strip_tags($line));355 $line = html_entity_decode($line);356 $line = preg_replace('/([^a-z| ])|(see)|(more)/i', '', $line);357 if ($line != '') {358 $rv['genre'] = trim(str_replace(' more', '', strip_tags($line)));359 $next_is_genre = 0;360 $got_genre = TRUE;361 } else {362 $next_is_genre--;363 }364 }365 if ($got_rating && $got_title && $got_genre) {366 break;367 }368 }369 fclose($f);370 return $rv;371 }372 public static function find_info($str, $key, $dont_follow = FALSE)373 {374 $file_nfo = $fn = [];375 switch ($key) {376 case urd_extsetinfo::SETTYPE_MOVIE:377 $fn[] = array('match_imdb_link', 'link');378 $fn[] = array('match_iafd_link', 'link');379 $fn[] = array('match_url', 'link');380 $fn[] = array('match_genre', 'moviegenre');381 $fn[] = array('match_title', 'name');382 $fn[] = array('match_subtitles', 'sublang');383 $fn[] = array('match_language', 'lang');384 $fn[] = array('match_title', 'year');385 $fn[] = array('match_format', 'movieformat');386 $fn[] = array('match_rating', 'score');387 $fn[] = array('match_duration', 'runtime');388 break;389 case urd_extsetinfo::SETTYPE_TVSERIES:390 $fn[] = array('match_imdb_link', 'link');391 $fn[] = array('match_tvrage_link', 'link');392 $fn[] = array('match_tvcom_link', 'link');393 $fn[] = array('match_url', 'link');394 $fn[] = array('match_genre', 'moviegenre');395 $fn[] = array('match_serietitle', 'name');396 $fn[] = array('match_title', 'name');397 $fn[] = array('match_subtitles', 'sublang');398 $fn[] = array('match_language', 'lang');399 $fn[] = array('match_title', 'year');400 $fn[] = array('match_format', 'movieformat');401 $fn[] = array('match_rating', 'score');402 $fn[] = array('match_duration', 'runtime');403 break;404 case urd_extsetinfo::SETTYPE_ALBUM:405 $fn[] = array('match_url', 'link');406 $fn[] = array('match_genre', 'musicgenre');407 $fn[] = array('match_albumtitle', 'name');408 $fn[] = array('match_year', 'year');409 $fn[] = array('match_band', 'band');410 $fn[] = array('match_format', 'musicformat');411 $fn[] = array('match_rating', 'score');412 $fn[] = array('match_duration', 'runtime');413 break;414 case urd_extsetinfo::SETTYPE_SOFTWARE:415 $fn[] = array('match_url', 'link');416 $fn[] = array('match_softwaretitle', 'name');417 $fn[] = array('match_software_os', 'os');418 $fn[] = array('match_language', 'lang');419 $fn[] = array('match_software_format', 'softwareformat');420 $fn[] = array('match_software_genre', 'softwaregenre');421 break;422 case urd_extsetinfo::SETTYPE_EBOOK: // usually no nfo files :(423 $fn[] = array('match_url', 'link');424 $fn[] = array('match_format', 'ebookformat');425 break;426 case urd_extsetinfo::SETTYPE_GAME:427 $fn[] = array('match_url', 'link');428 $fn[] = array('match_softwaretitle', 'name');429 $fn[] = array('match_software_os', 'os');430 $fn[] = array('match_language', 'lang');431 $fn[] = array('match_software_format', 'gameformat');432 $fn[] = array('match_software_genre', 'gamegenre');433 break;434 case urd_extsetinfo::SETTYPE_DOCUMENTARY:435 $fn[] = array('match_imdb_link', 'link');436 $fn[] = array('match_url', 'link');437 $fn[] = array('match_genre', 'moviegenre');438 $fn[] = array('match_title', 'name');439 $fn[] = array('match_subtitles', 'sublang');440 $fn[] = array('match_language', 'lang');441 $fn[] = array('match_title', 'year');442 $fn[] = array('match_rating', 'score');443 $fn[] = array('match_duration', 'runtime');444 break;445 case urd_extsetinfo::SETTYPE_TVSHOW:446 $fn[] = array('match_url', 'link');447 $fn[] = array('match_serietitle', 'name');448 $fn[] = array('match_title', 'name');449 $fn[] = array('match_subtitles', 'sublang');450 $fn[] = array('match_language', 'lang');451 $fn[] = array('match_title', 'year');452 $fn[] = array('match_rating', 'score');453 $fn[] = array('match_duration', 'runtime');454 break;455 case urd_extsetinfo::SETTYPE_IMAGE:456 default:457 break;458 }459 foreach ($str as $line) {460 foreach ($fn as $f) {461 $tmp = $f[0];462 nfo_parser::set_info($file_nfo, $f[1], nfo_parser::$tmp($line));463 }464 }465 if (!$dont_follow) {466 nfo_parser::get_link_info($file_nfo);467 }468 if ($key == urd_extsetinfo::SETTYPE_ALBUM) {469 if (isset($file_nfo['name']) && isset($file_nfo['band'])) {470 $file_nfo['name'] = $file_nfo['band'] . ' - ' . $file_nfo['name'];471 } elseif (isset($file_nfo['band'])) {472 $file_nfo['name'] = $file_nfo['band'];473 }474 }475 return $file_nfo;476 }477 public static function get_link_info(array &$file_nfo)478 {479 if (isset($file_nfo['link']) && preg_match('/imdb.(com|de|fr|es|it)/i', $file_nfo['link']) !== FALSE) {480 $rv = nfo_parser::parse_imdb_info($file_nfo['link']);481 if ($rv['name'] !== NULL) {482 $file_nfo['name'] = $rv['name'];483 }484 if ($rv['year'] !== NULL) {485 $file_nfo['year'] = $rv['year'];486 }487 if ($rv['rating'] !== NULL) {488 $file_nfo['score'] = $rv['rating'];489 }490 if ($rv['genre'] !== NULL) {491 $file_nfo['moviegenre'] = $rv['genre'];492 }493 }494 if (isset($file_nfo['link']) && strpos($file_nfo['link'], 'tvrage.com') !== FALSE) {495 $rv = nfo_parser::parse_tvrage_info($file_nfo['link']);496 if ($rv['name'] !== NULL) {497 $file_nfo['name'] = $rv['name'];498 }499 if ($rv['rating'] !== NULL) {500 $file_nfo['score'] = $rv['rating'];501 }502 }503 if (isset($file_nfo['link']) && strpos($file_nfo['link'], 'tv.com') !== FALSE) {504 $rv = nfo_parser::parse_tvcom_info($file_nfo['link']);505 if ($rv['name'] !== NULL) {506 $file_nfo['name'] = $rv['name'];507 }508 if ($rv['rating'] !== NULL) {509 $file_nfo['score'] = $rv['rating'];510 }511 if ($rv['year'] !== NULL) {512 $file_nfo['year'] = $rv['year'];513 }514 }515 }516 public static function parse_nfo_file($filename, $key)517 {518 $contents = file($filename);519 $info = nfo_parser::find_info($contents, $key, FALSE);520 return $info;521 }522}...

Full Screen

Full Screen

TokenMatcherTest.php

Source:TokenMatcherTest.php Github

copy

Full Screen

...267 }268 public function testItDoesNotMatchTagsWhenLineDoesNotMatchPattern(): void269 {270 $token = $this->createNonMatchingToken();271 self::assertFalse($this->tokenMatcher->match_Language($token));272 self::assertNull($token->match);273 }274 public function testItMatchesLanguageLine(): void275 {276 $token = $this->createTokenWithContents('#language:fr');277 self::assertTrue($this->tokenMatcher->match_Language($token));278 self::assertSame(TokenType::Language, $token->match?->tokenType);279 }280 public function testItChangesDialectAfterLanguageLine(): void281 {282 $token = $this->createTokenWithContents('#language:fr');283 $this->tokenMatcher->match_Language($token);284 $token = $this->createTokenWithContents('Scénario:');285 self::assertTrue($this->tokenMatcher->match_ScenarioLine($token));286 }287 private function createTokenWithContents(string $contents): Token288 {289 return new Token(new StringGherkinLine($contents, 1), new Location(1, 1));290 }291 private function createNonMatchingToken(): Token292 {293 return $this->createTokenWithContents('HELLO WORLD');294 }295}...

Full Screen

Full Screen

wwwIMDBcom.php

Source:wwwIMDBcom.php Github

copy

Full Screen

1<?php2/**************************************************************************************************3 SWISScenter Source45 This is one of a selection of scripts all designed to obtain information from the internet6 relating to the movies that the user has added to their database. It typically collects7 information such as title, genre, year of release, certificate, synopsis, directors and actors.89 *************************************************************************************************/1011class movie_wwwIMDBcom extends Parser implements ParserInterface {12 protected $site_url = 'http://www.imdb.com/';13 protected $search_url = 'http://www.imdb.com/find?s=tt&ttype=ft&ref_=fn_ft&q=';1415 protected $match_plot = 'Plot';16 protected $match_genre = 'Genre';17 protected $match_director = 'Director';18 protected $match_language = 'Language';19 protected $match_certificate = 'Certification';2021 public $supportedProperties = array (22 IMDBTT,23 TITLE,24 SYNOPSIS,25 ACTORS,26 ACTOR_IMAGES,27 DIRECTORS,28 GENRES,29 LANGUAGES,30 YEAR,31 CERTIFICATE,32 POSTER,33 EXTERNAL_RATING_PC,34 MATCH_PC35 );3637 public $settings = array (38 FULL_CAST => array("options" => array('Yes', 'No'),39 "default" => 'No')40 );4142 public static function getName() {43 return "www.IMDb.com";44 }4546 /**47 * Populate the page variable. This is the part of the html thats needed to get all the properties.48 *49 * @param array $search_params50 */5152 protected function populatePage($search_params) {53 if (isset($search_params['TITLE']) && !empty($search_params['TITLE']))54 $this->title = $search_params['TITLE'];55 if (isset($search_params['YEAR']) && !empty($search_params['YEAR']))56 $year = $search_params['YEAR'];5758 send_to_log(4, "Searching for details about " . $this->title . " " . $year . " online at " . $this->site_url);5960 // Check filename and title for an IMDb ID61 if (! (isset ($search_params['IGNORE_IMDBTT']) && $search_params['IGNORE_IMDBTT']) ) {62 send_to_log(4, "Searching for IMDb ID in file details.");63 $details = db_row("select * from movies where file_id=" . $this->id);64 $imdbtt = $this->checkForIMDBTT($details);65 }6667 $temp_title = $this->title;68 if (isset ($year))69 $temp_title .= " (" . $year . ")";7071 if (!$imdbtt) {72 // Use IMDb's internal search to get a list a possible matches73 $search_url = $this->search_url . str_replace('%20', '+', urlencode($temp_title));74 send_to_log(8, "Using IMDb internal search: " . $search_url);7576 // Download page and decode HTML entities77 $html = html_entity_decode(file_get_contents($search_url), ENT_QUOTES);78 $html = html_entity_decode(ParserUtil :: decodeHexEntities($html), ENT_QUOTES, 'ISO-8859-15');7980 // Examine returned page81 if (strpos($html, $this->getNoMatchFoundHTML()) > 0) {82 // No matches found83 $this->accuracy = 0;84 send_to_log(4, "No matches");85 } elseif (strpos($html, $this->getSearchPageHTML()) > 0) {86 // Search results for a match87 send_to_log(8, "Multiple IMDb matches...");8889 if ((preg_match('/\((\d{4})\)/', $details["TITLE"], $title_year) != 0) || (preg_match('/\((\d{4})\)/', $temp_title, $title_year) != 0)) {90 send_to_log(8, "Found year in the title: " . $title_year[0]);91 $html = preg_replace('/<\/a>[ \(\)IV]*\((\d{4})\)/Ui', ' ($1)</a>', $html);92 }93 $html = substr($html, strpos($html, "Titles"));94 $matches = get_urls_from_html($html, '\/title\/tt\d+\/');95 $index = ParserUtil :: most_likely_match($temp_title, $matches[2], $this->accuracy, $year);9697 // If we are sure that we found a good result, then get the file details.98 if ($this->accuracy > 75) {99 $url_imdb = add_site_to_url($matches[1][$index], $this->site_url);100 $url_imdb = substr($url_imdb, 0, strpos($url_imdb, "?") - 1);101 send_to_log(8, 'Using IMDb ID: '.$url_imdb);102 }103 } else {104 // Direct hit on the title105 $url_imdb = $this->site_url . "title/" . $this->findIMDBTTInPage($html);106 send_to_log(8, 'Direct IMDb hit: '.$url_imdb);107 $this->accuracy = 100;108 }109 } else {110 // Use IMDb ID to get movie page111 $url_imdb = $this->site_url . 'title/' . $imdbtt;112 send_to_log(8, 'Using IMDb ID: '.$url_imdb);113 $this->accuracy = 100;114 }115116 // Download the combined view of the required page117 if ($this->accuracy >= 75) {118 $html = html_entity_decode(file_get_contents($url_imdb . '/combined'), ENT_QUOTES);119 $html = html_entity_decode(ParserUtil :: decodeHexEntities($html), ENT_QUOTES, 'ISO-8859-15');120 $this->page = $this->getRelevantPartOfHTML($html);121 if (isset ($this->page)) {122 send_to_log(8, "Returning true..." . $url_imdb);123 return true;124 }125 }126 return false;127 }128 protected function getSearchPageHTML(){129 return "<title>Find - IMDb</title>";130 }131 protected function getNoMatchFoundHTML(){132 return "No Matches.";133 }134135 /**136 * Get the relevant part of the page137 */138 private function getRelevantPartOfHTML($html) {139 $start = strpos($html, "<div id=\"pagecontent\">");140 if ($start !== false) {141 $end = strpos($html, "<a name=\"comment\">");142 if ($end !== false) {143 return substr($html, $start, $end - $start + 1);144 }145 }146 }147148 /**149 * Properties supported by this parser.150 *151 */152153 protected function parseYear() {154 $html = $this->page;155 $year = preg_get('/<b>.*\((\d{4})\).*<\/b>/Us', $html);156 if (!empty($year)) {157 $this->setProperty(YEAR, $year);158 return $year;159 }160 }161 protected function parseTitle() {162 $html = $this->page;163 if (strlen($html) !== 0) {164 $start = strpos($html, "<h1>") + 4;165 $end = strpos($html, "<span>", $start + 1);166 $title = substr($html, $start, $end - $start);167 }168 $title = trim(preg_replace('/\"/', '', ParserUtil :: decodeHexEntities($title)));169 if (isset($title) && !empty($title)) {170 $this->setProperty(TITLE, $title);171 return $title;172 }173 }174 protected function parseSynopsis() {175 $html = $this->page;176 $start = strpos($html,"<h5>$this->match_plot:</h5>");177 if ($start !== false) {178 $end = strpos($html,"</div>", $start + 1);179 if ($end !== false) {180 $html_synopsis = substr($html,$start,$end-$start+1);181 $matches = preg_get("/class=\"info-content\">(.*)</Usm", $html_synopsis);182 $synopsis = trim(trim($matches), " |");183 if (isset($synopsis) && !empty($synopsis)) {184 $this->setProperty(SYNOPSIS, $synopsis);185 return $synopsis;186 }187 }188 }189 }190 protected function parseIMDBTT() {191 $imdbtt = $this->findIMDBTTInPage($this->page);192 if (isset($imdbtt) && !empty($imdbtt)) {193 $this->setProperty(IMDBTT, $imdbtt);194 return $imdbtt;195 }196 }197 protected function findIMDBTTInPage($html) {198 return preg_get('~;id=(tt\d+);~U', $html);199 }200 protected function parseActors() {201 $html = $this->page;202 $start = strpos($html, "<table class=\"cast\">");203 if (get_sys_pref(str_replace('movie_', '', get_class($this)).'_FULL_CAST', $this->settings[FULL_CAST]["default"]) == 'YES')204 $end = strpos($html, "</table>", $start + 1);205 else206 $end = (strpos($html, "<small>", $start + 1) !== false ? strpos($html, "<small>", $start + 1) : strpos($html, "</table>", $start + 1));207 $html_actors = substr($html, $start, $end - $start);208 $matches = get_urls_from_html($html_actors, '\/name\/nm\d+\/');209 for ($i = 0; $i < count($matches[2]); $i++) {210 if (strlen($matches[2][$i]) == 0) {211 array_splice($matches[2], $i, 1);212 $i--;213 }214 }215 $actors = ParserUtil :: decodeHexEntitiesList($matches[2]);216 if (isset($actors) && !empty($actors)) {217 $this->setProperty(ACTORS, $actors);218 return $actors;219 }220 }221 protected function parseActorImages() {222 $html = $this->page;223 $start = strpos($html, "<table class=\"cast\">");224 if (get_sys_pref(str_replace('movie_', '', get_class($this)).'_FULL_CAST', $this->settings[FULL_CAST]["default"]) == 'YES')225 $end = strpos($html, "</table>", $start + 1);226 else227 $end = strpos($html, "<small>", $start + 1);228 $html_actors = substr($html, $start, $end - $start);229 preg_match_all('/<img src="(.*)" width="\d{2}" height="\d{2}" border="0">.*<\/td><td class="nm"><a href="\/name\/(nm\d+)\/" onclick=".*">(.*)<\/a>/Us', $html_actors, $matches);230 $actors = array();231 for ($i = 0; $i < count($matches[0]); $i++) {232 if (strpos($matches[1][$i], 'no_photo') === false && strlen($matches[2][$i]) > 0) {233 // Remove the resize attributes (_V1._SYxx_SXxx_)234 $matches[1][$i] = preg_replace('/\._V\d\._.*\.jpg/U', '.jpg', $matches[1][$i]);235236 $actors[] = array('ID' => $matches[2][$i],237 'IMAGE' => $matches[1][$i],238 'NAME' => ParserUtil :: decodeHexEntities($matches[3][$i]));239 }240 }241 if (isset($actors) && !empty($actors)) {242 $this->setProperty(ACTOR_IMAGES, $actors);243 return $actors;244 }245 }246 protected function parseDirectors() {247 $html = $this->page;248 $start = strpos($html, "<h5>$this->match_director");249 if ($start !== false) {250 $end = strpos($html,"</div>", $start + 1);251 if ($end !== false) {252 $html_directed = substr($html, $start, $end - $start);253 $matches = get_urls_from_html($html_directed, '\/name\/nm\d+\/');254 if (isset($matches[2])&& !empty($matches[2])) {255 $this->setProperty(DIRECTORS, $matches[2]);256 return $matches[2];257 }258 }259 }260 }261 protected function parseGenres() {262 $html = $this->page;263 $start = strpos($html,"<h5>$this->match_genre:</h5>");264 if ($start !== false) {265 $end = strpos($html,"</div>", $start + 1);266 if ($end !== false) {267 $html_genres = substr($html,$start,$end-$start);268 $matches = get_urls_from_html($html_genres,'\/Sections\/Genres\/');269 if (isset($matches[2]) && !empty($matches[2])) {270 $this->setProperty(GENRES, $matches[2]);271 return $matches[2];272 }273 }274 }275 }276 protected function parseLanguages() {277 $html = $this->page;278 $start = strpos($html,"<h5>$this->match_language:</h5>");279 if ($start !== false) {280 $end = strpos($html,"</div>", $start + 1);281 if ($end !== false) {282 $html_langs = str_replace("\n","",substr($html,$start,$end-$start));283 $matches = get_urls_from_html($html_langs,'\/language\/');284 $new_languages = $matches[2];285 if (isset($new_languages) && !empty($new_languages)) {286 $this->setProperty(LANGUAGES, $new_languages);287 return $new_languages;288 }289 }290 }291 }292 protected function parseExternalRatingPc() {293 $html = $this->page;294 $user_rating = preg_get('/<div.*class=\"starbar-meta\">.*<b>(.*)\/10<\/b>/Usm', $html);295 if (!empty ($user_rating)) {296 $user_rating = intval($user_rating * 10);297 $this->setProperty(EXTERNAL_RATING_PC, $user_rating);298 return $user_rating;299 }300 }301 protected function parseCertificate() {302 $html = $this->page;303 $certlist = array ();304 foreach (explode('|', substr_between_strings($html, $this->match_certificate.':', '</div>')) as $cert) {305 $cert = preg_replace('/\(.*\)/U', '', $cert);306 $country = trim(substr($cert, 0, strpos($cert, ':')));307 $certificate = trim(substr($cert, strpos($cert, ':') + 1)) . ' ';308 $certlist[$country] = substr($certificate, 0, strpos($certificate, ' '));309 }310 switch (get_rating_scheme_name())311 {312 case 'FSK':313 if (isset($certlist["Germany"])) {314 $rating = 'FSK '.$certlist["Germany"];315 break;316 }317 case 'Kijkwijzer':318 if (isset($certlist["Netherlands"])) {319 $rating = $certlist["Netherlands"];320 break;321 }322 case 'BBFC':323 if (isset($certlist["UK"])) {324 $rating = $certlist["UK"];325 break;326 }327 default:328 if (isset($certlist["USA"])) {329 $rating = $certlist["USA"];330 }331 }332 if(isset($rating) && !empty($rating)){333 $this->setProperty(CERTIFICATE, $rating);334 return $rating;335 }336 }337 protected function parsePoster() {338 $html = $this->page;339 $matches = get_images_from_html($html);340 $img_addr = $matches[1][0];341 if (file_ext($img_addr) == 'jpg' && !stristr($img_addr, 'addposter')) {342 // Remove the resize attributes (_V1._SYxx_SXxx_)343 $img_addr = preg_replace('/\._V\d\._.*\.jpg/U', '.jpg', $img_addr);344 if (url_exists($img_addr)) {345 $this->setProperty(POSTER, $img_addr);346 return $img_addr;347 }348 }349 }350 protected function parseMatchPc() {351 if (isset ($this->accuracy)) {352 $this->setProperty(MATCH_PC, $this->accuracy);353 return $this->accuracy;354 }355 }356} ...

Full Screen

Full Screen

TokenMatcher.php

Source:TokenMatcher.php Github

copy

Full Screen

...160 return true;161 }162 return false;163 }164 public function match_Language(Token $token): bool165 {166 if ($token->line && preg_match(self::LANGUAGE_PATTERN, $token->line->getLineText(0), $matches)) {167 /** @var array{0: non-empty-string, 1: non-empty-string} $matches */168 $language = $matches[1];169 $this->setTokenMatched($token, TokenType::Language, $language);170 $this->currentDialect = $this->dialectProvider->getDialect($language, $token->getLocation());171 return true;172 }173 return false;174 }175 private function unescapeDocString(string $text): string176 {177 if ($this->activeDocStringSeparator === GherkinLanguageConstants::DOCSTRING_SEPARATOR) {178 return StringUtils::replace($text, ['\\"\\"\\"' => GherkinLanguageConstants::DOCSTRING_SEPARATOR]);...

Full Screen

Full Screen

TokenMatcherInterface.php

Source:TokenMatcherInterface.php Github

copy

Full Screen

...21 public function match_ExamplesLine(Token $token): bool;22 public function match_StepLine(Token $token): bool;23 public function match_DocStringSeparator(Token $token): bool;24 public function match_TableRow(Token $token): bool;25 public function match_Language(Token $token): bool;26 public function match_Other(Token $token): bool;27 public function reset(): void;28}...

Full Screen

Full Screen

match_Language

Using AI Code Generation

copy

Full Screen

1$parser = new Parser;2$parser->match_Language('1.php');3$parser = new Parser;4$parser->match_Language('2.php');5$parser = new Parser;6$parser->match_Language('3.php');7$parser = new Parser;8$parser->match_Language('4.php');9$parser = new Parser;10$parser->match_Language('5.php');11$parser = new Parser;12$parser->match_Language('6.php');13$parser = new Parser;14$parser->match_Language('7.php');15$parser = new Parser;16$parser->match_Language('8.php');17$parser = new Parser;18$parser->match_Language('9.php');19$parser = new Parser;20$parser->match_Language('10.php');21$parser = new Parser;22$parser->match_Language('11.php');23$parser = new Parser;24$parser->match_Language('12.php');25$parser = new Parser;26$parser->match_Language('13.php');27$parser = new Parser;28$parser->match_Language('14.php');29$parser = new Parser;

Full Screen

Full Screen

match_Language

Using AI Code Generation

copy

Full Screen

1require_once 'Parser.php';2$parser = new Parser();3$parser->match_Language('1.php');4require_once 'Parser.php';5$parser = new Parser();6$parser->match_Language('2.php');7require_once 'Parser.php';8$parser = new Parser();9$parser->match_Language('3.php');10require_once 'Parser.php';11$parser = new Parser();12$parser->match_Language('4.php');13require_once 'Parser.php';14$parser = new Parser();15$parser->match_Language('5.php');16require_once 'Parser.php';17$parser = new Parser();18$parser->match_Language('6.php');19require_once 'Parser.php';20$parser = new Parser();21$parser->match_Language('7.php');22require_once 'Parser.php';23$parser = new Parser();24$parser->match_Language('8.php');25require_once 'Parser.php';26$parser = new Parser();27$parser->match_Language('9.php');28require_once 'Parser.php';29$parser = new Parser();30$parser->match_Language('10.php');31require_once 'Parser.php';32$parser = new Parser();33$parser->match_Language('11.php');34require_once 'Parser.php';35$parser = new Parser();36$parser->match_Language('12.php');37require_once 'Parser.php';

Full Screen

Full Screen

match_Language

Using AI Code Generation

copy

Full Screen

1$parser = new Parser();2$parser->match_Language("Hello World");3$parser = new Parser();4$parser->match_Language("Hello World");5$parser = new Parser();6$parser->match_Language("Hello World");7$parser = new Parser();8$parser->match_Language("Hello World");9$parser = new Parser();10$parser->match_Language("Hello World");11$parser = new Parser();12$parser->match_Language("Hello World");13$parser = new Parser();14$parser->match_Language("Hello World");15$parser = new Parser();16$parser->match_Language("Hello World");17$parser = new Parser();18$parser->match_Language("Hello World");19$parser = new Parser();20$parser->match_Language("Hello World");21$parser = new Parser();22$parser->match_Language("Hello World");23$parser = new Parser();24$parser->match_Language("Hello World");25$parser = new Parser();26$parser->match_Language("Hello World");27$parser = new Parser();28$parser->match_Language("Hello World");29$parser = new Parser();

Full Screen

Full Screen

match_Language

Using AI Code Generation

copy

Full Screen

1require_once('Parser.php');2$parser = new Parser();3$parser->match_language('1.php');4require_once('Parser.php');5$parser = new Parser();6$parser->match_language('2.php');7require_once('Parser.php');8$parser = new Parser();9$parser->match_language('3.php');10require_once('Parser.php');11$parser = new Parser();12$parser->match_language('4.php');13require_once('Parser.php');14$parser = new Parser();15$parser->match_language('5.php');16require_once('Parser.php');17$parser = new Parser();18$parser->match_language('6.php');19require_once('Parser.php');20$parser = new Parser();21$parser->match_language('7.php');22require_once('Parser.php');23$parser = new Parser();24$parser->match_language('8.php');25require_once('Parser.php');26$parser = new Parser();27$parser->match_language('9.php');28require_once('Parser.php');29$parser = new Parser();30$parser->match_language('10.php');31require_once('Parser.php');32$parser = new Parser();33$parser->match_language('11.php');34require_once('Parser.php');35$parser = new Parser();36$parser->match_language('12.php');37require_once('Parser.php');38$parser = new Parser();39$parser->match_language('

Full Screen

Full Screen

match_Language

Using AI Code Generation

copy

Full Screen

1$parser = new Parser();2$parser->match_Language($text, $lang_code);3$parser = new Parser();4$parser->match_Language($text, $lang_name);5$parser = new Parser();6$parser->match_Language($text, $lang_code);7$parser = new Parser();8$parser->match_Language($text, $lang_name);9$parser = new Parser();10$parser->match_Language($text, $lang_code);11$parser = new Parser();12$parser->match_Language($text, $lang_name);13$parser = new Parser();14$parser->match_Language($text, $lang_code);15$parser = new Parser();16$parser->match_Language($text, $lang_name);17$parser = new Parser();18$parser->match_Language($text, $lang_code);19$parser = new Parser();20$parser->match_Language($text, $lang_name);

Full Screen

Full Screen

match_Language

Using AI Code Generation

copy

Full Screen

1$parser = new Parser();2$parser->match_Language("test.php");3$parser = new Parser();4$parser->match_Language("/home/username/test.php");5$parser = new Parser();6$parser->match_Language("test.php", 1);7$parser = new Parser();8$parser->match_Language("/home/username/test.php", 1);9$parser = new Parser();10$parser->match_Language("/home/username/test.php", 1);11$parser = new Parser();12$parser->match_Language("/home/username/test.php", 1);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful