Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
retypos-adapter
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
eterfund
retypos-adapter
Commits
15722c6a
Commit
15722c6a
authored
Sep 17, 2018
by
Георгий Попов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix typosClientInterface to work with additional title and subtitle fields.
parent
f5887ce9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
11 deletions
+13
-11
MyClientInterface.php
example/MyClientInterface.php
+1
-1
TyposClientInterface.php
src/TyposClientInterface.php
+12
-10
No files found.
example/MyClientInterface.php
View file @
15722c6a
...
...
@@ -21,7 +21,7 @@ class MyClientInterface extends TyposClientInterface {
*/
protected
function
getArticleFromLink
(
string
$link
)
{
return
new
TyposArticle
(
0
,
""
);
return
new
TyposArticle
(
0
,
""
,
""
,
""
);
}
/**
...
...
src/TyposClientInterface.php
View file @
15722c6a
...
...
@@ -173,10 +173,12 @@ abstract class TyposClientInterface
* @param $text
*
* @return string Text with typo replaced by corrected
* @throws \Exception
If something goes wrong
* @throws \Exception If something goes wrong
*/
private
function
replaceTypoInText
(
string
$typo
,
string
$corrected
,
string
$context
,
$text
)
{
// Strip all tags from text
// Also copy input string
$originalText
=
$text
;
$text
=
strip_tags
(
$text
);
// BUG# 13121
...
...
@@ -185,14 +187,13 @@ abstract class TyposClientInterface
// Find all typos in text, capture an offset of each typo
$typos
=
[];
preg_match_all
(
"#
{
$typo
}
#"
,
$text
,
$typos
,
PREG_OFFSET_CAPTURE
);
$typos
=
$typos
[
0
];
preg_match
(
"#
{
$typo
}
#"
,
$text
,
$typos
,
PREG_OFFSET_CAPTURE
);
if
(
!
isset
(
$typos
[
0
])
)
{
if
(
count
(
$typos
)
==
0
)
{
// Check for already fixed typo
preg_match
_all
(
"#
{
$corrected
}
#"
,
$text
,
$typos
,
PREG_OFFSET_CAPTURE
);
preg_match
(
"#
{
$corrected
}
#"
,
$text
,
$typos
,
PREG_OFFSET_CAPTURE
);
if
(
isset
(
$typos
[
0
][
1
])
)
{
if
(
count
(
$typos
)
!=
0
)
{
throw
new
\Exception
(
"Already fixed"
,
208
);
}
...
...
@@ -201,17 +202,17 @@ abstract class TyposClientInterface
// Find a context in text, capture it offset
$contextMatch
=
[];
preg_match
_all
(
"#
{
$context
}
#"
,
$text
,
$contextMatch
,
PREG_OFFSET_CAPTURE
);
preg_match
(
"#
{
$context
}
#"
,
$text
,
$contextMatch
,
PREG_OFFSET_CAPTURE
);
// If a context was changed then report an error,
// cannot locate typo in a new context, must be
// fixed manually
if
(
!
isset
(
$contextMatch
[
0
])
)
{
if
(
count
(
$contextMatch
)
==
0
)
{
throw
new
\Exception
(
"Context not found"
,
405
);
}
$contextMatch
=
$contextMatch
[
0
];
$contextOffset
=
$contextMatch
[
0
][
1
];
$contextOffset
=
$contextMatch
[
1
];
// Find a concrete typo that we want to fix
$indexOfTypo
=
null
;
...
...
@@ -234,7 +235,7 @@ abstract class TyposClientInterface
return
$match
[
0
];
},
$
t
ext
);
$
originalT
ext
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment