Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Feeds
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MickGe
Feeds
Commits
f4d0e7bb
Commit
f4d0e7bb
authored
4 years ago
by
Andrew Dolgov
Browse files
Options
Downloads
Patches
Plain Diff
* af_redditimgur: optionally import score
* add pluginhost->set_array() to set many plugin settings at once
parent
72c04123
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
classes/pluginhost.php
+14
-2
14 additions, 2 deletions
classes/pluginhost.php
plugins/af_redditimgur/init.php
+35
-5
35 additions, 5 deletions
plugins/af_redditimgur/init.php
with
49 additions
and
7 deletions
classes/pluginhost.php
+
14
−
2
View file @
f4d0e7bb
...
@@ -469,7 +469,7 @@ class PluginHost {
...
@@ -469,7 +469,7 @@ class PluginHost {
}
}
}
}
function
set
(
Plugin
$sender
,
string
$name
,
$value
,
bool
$sync
=
true
)
{
function
set
(
Plugin
$sender
,
string
$name
,
$value
)
{
$idx
=
get_class
(
$sender
);
$idx
=
get_class
(
$sender
);
if
(
!
isset
(
$this
->
storage
[
$idx
]))
if
(
!
isset
(
$this
->
storage
[
$idx
]))
...
@@ -477,7 +477,19 @@ class PluginHost {
...
@@ -477,7 +477,19 @@ class PluginHost {
$this
->
storage
[
$idx
][
$name
]
=
$value
;
$this
->
storage
[
$idx
][
$name
]
=
$value
;
if
(
$sync
)
$this
->
save_data
(
get_class
(
$sender
));
$this
->
save_data
(
get_class
(
$sender
));
}
function
set_array
(
Plugin
$sender
,
array
$params
)
{
$idx
=
get_class
(
$sender
);
if
(
!
isset
(
$this
->
storage
[
$idx
]))
$this
->
storage
[
$idx
]
=
array
();
foreach
(
$params
as
$name
=>
$value
)
$this
->
storage
[
$idx
][
$name
]
=
$value
;
$this
->
save_data
(
get_class
(
$sender
));
}
}
function
get
(
Plugin
$sender
,
string
$name
,
$default_value
=
false
)
{
function
get
(
Plugin
$sender
,
string
$name
,
$default_value
=
false
)
{
...
...
This diff is collapsed.
Click to expand it.
plugins/af_redditimgur/init.php
+
35
−
5
View file @
f4d0e7bb
...
@@ -6,6 +6,7 @@ class Af_RedditImgur extends Plugin {
...
@@ -6,6 +6,7 @@ class Af_RedditImgur extends Plugin {
private
$domain_blacklist
=
[
"github.com"
];
private
$domain_blacklist
=
[
"github.com"
];
private
$dump_json_data
=
false
;
private
$dump_json_data
=
false
;
private
$fallback_preview_urls
=
[];
private
$fallback_preview_urls
=
[];
private
$default_max_score
=
100
;
function
about
()
{
function
about
()
{
return
array
(
null
,
return
array
(
null
,
...
@@ -35,6 +36,8 @@ class Af_RedditImgur extends Plugin {
...
@@ -35,6 +36,8 @@ class Af_RedditImgur extends Plugin {
$enable_content_dupcheck
=
$this
->
host
->
get
(
$this
,
"enable_content_dupcheck"
);
$enable_content_dupcheck
=
$this
->
host
->
get
(
$this
,
"enable_content_dupcheck"
);
$reddit_to_teddit
=
$this
->
host
->
get
(
$this
,
"reddit_to_teddit"
);
$reddit_to_teddit
=
$this
->
host
->
get
(
$this
,
"reddit_to_teddit"
);
$apply_nsfw_tags
=
$this
->
host
->
get_array
(
$this
,
"apply_nsfw_tags"
);
$apply_nsfw_tags
=
$this
->
host
->
get_array
(
$this
,
"apply_nsfw_tags"
);
$max_score
=
$this
->
host
->
get
(
$this
,
"max_score"
,
$this
->
default_max_score
);
$import_score
=
$this
->
host
->
get
(
$this
,
"import_score"
);
?>
?>
<div
dojoType=
"dijit.layout.AccordionPane"
<div
dojoType=
"dijit.layout.AccordionPane"
...
@@ -84,6 +87,15 @@ class Af_RedditImgur extends Plugin {
...
@@ -84,6 +87,15 @@ class Af_RedditImgur extends Plugin {
</label>
</label>
</fieldset>
</fieldset>
<fieldset
class=
'narrow'
>
<label
class=
'checkbox'
>
<?=
\Controls\checkbox_tag
(
"import_score"
,
$import_score
)
?>
<?=
__
(
"Import score, limit maximum to:"
)
?>
<input
dojoType=
"dijit.form.TextBox"
name=
"max_score"
size=
"20"
placeholder=
"
<?=
$this
->
default_max_score
?>
"
value=
"
<?=
$max_score
?>
"
>
</label>
</fieldset>
<hr/>
<hr/>
<?=
\Controls\submit_tag
(
__
(
"Save"
))
?>
<?=
\Controls\submit_tag
(
__
(
"Save"
))
?>
</form>
</form>
...
@@ -97,11 +109,17 @@ class Af_RedditImgur extends Plugin {
...
@@ -97,11 +109,17 @@ class Af_RedditImgur extends Plugin {
$enable_content_dupcheck
=
checkbox_to_sql_bool
(
$_POST
[
"enable_content_dupcheck"
]
??
""
);
$enable_content_dupcheck
=
checkbox_to_sql_bool
(
$_POST
[
"enable_content_dupcheck"
]
??
""
);
$reddit_to_teddit
=
checkbox_to_sql_bool
(
$_POST
[
"reddit_to_teddit"
]
??
""
);
$reddit_to_teddit
=
checkbox_to_sql_bool
(
$_POST
[
"reddit_to_teddit"
]
??
""
);
$apply_nsfw_tags
=
FeedItem_Common
::
normalize_categories
(
explode
(
","
,
$_POST
[
"apply_nsfw_tags"
]
??
""
));
$apply_nsfw_tags
=
FeedItem_Common
::
normalize_categories
(
explode
(
","
,
$_POST
[
"apply_nsfw_tags"
]
??
""
));
$import_score
=
checkbox_to_sql_bool
(
$_POST
[
"import_score"
]
??
""
);
$this
->
host
->
set
(
$this
,
"enable_readability"
,
$enable_readability
,
false
);
$max_score
=
(
int
)
$_POST
[
'max_score'
];
$this
->
host
->
set
(
$this
,
"reddit_to_teddit"
,
$reddit_to_teddit
,
false
);
$this
->
host
->
set
(
$this
,
"enable_content_dupcheck"
,
$enable_content_dupcheck
);
$this
->
host
->
set_array
(
$this
,
[
$this
->
host
->
set
(
$this
,
"apply_nsfw_tags"
,
$apply_nsfw_tags
);
"enable_readability"
=>
$enable_readability
,
"reddit_to_teddit"
=>
$reddit_to_teddit
,
"enable_content_dupcheck"
=>
$enable_content_dupcheck
,
"apply_nsfw_tags"
=>
$apply_nsfw_tags
,
"import_score"
=>
$import_score
,
"max_score"
=>
$max_score
]);
echo
__
(
"Configuration saved"
);
echo
__
(
"Configuration saved"
);
}
}
...
@@ -213,11 +231,19 @@ class Af_RedditImgur extends Plugin {
...
@@ -213,11 +231,19 @@ class Af_RedditImgur extends Plugin {
return
$found
;
return
$found
;
}
}
/* function score_convert(int $value, int $from1, int $from2, int $to1, int $to2) {
return ($value - $from1) / ($from2 - $from1) * ($to2 - $to1) + $to1;
} */
private
function
inline_stuff
(
&
$article
,
&
$doc
,
$xpath
)
{
private
function
inline_stuff
(
&
$article
,
&
$doc
,
$xpath
)
{
$max_score
=
(
int
)
$this
->
host
->
get
(
$this
,
"max_score"
,
$this
->
default_max_score
);
$import_score
=
(
bool
)
$this
->
host
->
get
(
$this
,
"import_score"
,
$this
->
default_max_score
);
$found
=
false
;
$found
=
false
;
$post_is_nsfw
=
false
;
$post_is_nsfw
=
false
;
$num_comments
=
0
;
$num_comments
=
0
;
$score
=
0
;
$apply_nsfw_tags
=
FeedItem_Common
::
normalize_categories
(
$this
->
host
->
get_array
(
$this
,
"apply_nsfw_tags"
,
[]));
$apply_nsfw_tags
=
FeedItem_Common
::
normalize_categories
(
$this
->
host
->
get_array
(
$this
,
"apply_nsfw_tags"
,
[]));
// embed before reddit <table> post layout
// embed before reddit <table> post layout
...
@@ -246,6 +272,7 @@ class Af_RedditImgur extends Plugin {
...
@@ -246,6 +272,7 @@ class Af_RedditImgur extends Plugin {
$data
=
$child
[
"data"
];
$data
=
$child
[
"data"
];
$over_18
=
$data
[
"over_18"
]
??
0
==
1
;
$over_18
=
$data
[
"over_18"
]
??
0
==
1
;
$score
+=
$data
[
'score'
]
??
0
;
$num_comments
+=
$data
[
"num_comments"
]
??
0
;
$num_comments
+=
$data
[
"num_comments"
]
??
0
;
if
(
$over_18
)
{
if
(
$over_18
)
{
...
@@ -292,6 +319,9 @@ class Af_RedditImgur extends Plugin {
...
@@ -292,6 +319,9 @@ class Af_RedditImgur extends Plugin {
$article
[
"num_comments"
]
=
$num_comments
;
$article
[
"num_comments"
]
=
$num_comments
;
if
(
$import_score
&&
$score
>
0
)
$article
[
"score_modifier"
]
=
(
$article
[
"score_modifier"
]
??
0
)
+
(
$score
>
$max_score
?
$max_score
:
$score
);
if
(
$found
)
{
if
(
$found
)
{
Debug
::
log
(
"JSON: found media data, skipping further processing of content"
,
Debug
::
$LOG_VERBOSE
);
Debug
::
log
(
"JSON: found media data, skipping further processing of content"
,
Debug
::
$LOG_VERBOSE
);
$this
->
remove_post_thumbnail
(
$doc
,
$xpath
);
$this
->
remove_post_thumbnail
(
$doc
,
$xpath
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment