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
4cf0f9a9
Commit
4cf0f9a9
authored
11 years ago
by
Andrew Dolgov
Browse files
Options
Downloads
Patches
Plain Diff
greaderimport: add command line mode
parent
4c92878f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
classes/pluginhost.php
+3
-1
3 additions, 1 deletion
classes/pluginhost.php
plugins/greaderstarredimport/init.php
+64
-18
64 additions, 18 deletions
plugins/greaderstarredimport/init.php
update.php
+3
-2
3 additions, 2 deletions
update.php
with
70 additions
and
21 deletions
classes/pluginhost.php
+
3
−
1
View file @
4cf0f9a9
...
...
@@ -172,10 +172,12 @@ class PluginHost {
return
false
;
}
function
add_command
(
$command
,
$description
,
$sender
)
{
function
add_command
(
$command
,
$description
,
$sender
,
$suffix
=
""
,
$arghelp
=
""
)
{
$command
=
str_replace
(
"-"
,
"_"
,
strtolower
(
$command
));
$this
->
commands
[
$command
]
=
array
(
"description"
=>
$description
,
"suffix"
=>
$suffix
,
"arghelp"
=>
$arghelp
,
"class"
=>
$sender
);
}
...
...
This diff is collapsed.
Click to expand it.
plugins/greaderstarredimport/init.php
+
64
−
18
View file @
4cf0f9a9
...
...
@@ -17,25 +17,68 @@ class GreaderStarredImport extends Plugin {
$this
->
link
=
$host
->
get_link
();
$this
->
host
=
$host
;
$host
->
add_command
(
"greader-import"
,
"import data in Google Reader JSON format"
,
$this
,
":"
,
"FILE"
);
$host
->
add_hook
(
$host
::
HOOK_PREFS_TAB
,
$this
);
}
function
greader_import
(
$args
)
{
$file
=
$args
[
'greader_import'
];
if
(
!
file_exists
(
$file
))
{
_debug
(
"file not found:
$file
"
);
return
;
}
_debug
(
"please enter your username:"
);
$username
=
db_escape_string
(
$this
->
link
,
trim
(
read_stdin
()));
_debug
(
"looking up user:
$username
..."
);
$result
=
db_query
(
$this
->
link
,
"SELECT id FROM ttrss_users
WHERE login = '
$username
'"
);
if
(
db_num_rows
(
$result
)
==
0
)
{
_debug
(
"user not found."
);
return
;
}
$owner_uid
=
db_fetch_result
(
$result
,
0
,
"id"
);
_debug
(
"processing:
$file
(owner_uid:
$owner_uid
)"
);
$this
->
import
(
$file
,
$owner_uid
);
}
function
get_prefs_js
()
{
return
file_get_contents
(
dirname
(
__FILE__
)
.
"/init.js"
);
}
function
import
()
{
function
import
(
$file
=
false
,
$owner_uid
=
0
)
{
header
(
"Content-Type: text/html"
);
if
(
!
$file
)
{
header
(
"Content-Type: text/html"
);
if
(
is_file
(
$_FILES
[
'starred_file'
][
'tmp_name'
]))
{
$doc
=
json_decode
(
file_get_contents
(
$_FILES
[
'starred_file'
][
'tmp_name'
]),
true
);
if
(
is_file
(
$_FILES
[
'starred_file'
][
'tmp_name'
]))
{
$doc
=
json_decode
(
file_get_contents
(
$_FILES
[
'starred_file'
][
'tmp_name'
]),
true
);
}
else
{
print_error
(
__
(
'No file uploaded.'
));
return
;
}
}
else
{
print_error
(
__
(
'No file uploaded.'
));
return
;
$doc
=
json_decode
(
file_get_contents
(
$file
),
true
);
}
$sql_set_marked
=
strtolower
(
$_FILES
[
'starred_file'
][
'name'
])
==
'starred.json'
?
'true'
:
'false'
;
if
(
$file
)
{
$sql_set_marked
=
strtolower
(
basename
(
$file
))
==
'starred.json'
?
'true'
:
'false'
;
_debug
(
"will set articles as starred:
$sql_set_marked
"
);
}
else
{
$sql_set_marked
=
strtolower
(
$_FILES
[
'starred_file'
][
'name'
])
==
'starred.json'
?
'true'
:
'false'
;
}
if
(
$doc
)
{
if
(
isset
(
$doc
[
'items'
]))
{
...
...
@@ -66,12 +109,16 @@ class GreaderStarredImport extends Plugin {
$processed
++
;
$imported
+=
(
int
)
$this
->
create_article
(
$guid
,
$title
,
$imported
+=
(
int
)
$this
->
create_article
(
$owner_uid
,
$guid
,
$title
,
$updated
,
$link
,
$content
,
$author
,
$sql_set_marked
);
}
print
"<p style='text-align : center'>"
.
T_sprintf
(
"All done. %d out of %d articles imported."
,
$imported
,
$processed
)
.
"</p>"
;
if
(
$file
)
{
_debug
(
sprintf
(
"All done. %d of %d articles imported."
,
$imported
,
$processed
));
}
else
{
print
"<p style='text-align : center'>"
.
T_sprintf
(
"All done. %d out of %d articles imported."
,
$imported
,
$processed
)
.
"</p>"
;
}
}
else
{
print_error
(
__
(
'The document has incorrect format.'
));
...
...
@@ -81,18 +128,17 @@ class GreaderStarredImport extends Plugin {
print_error
(
__
(
'Error while parsing document.'
));
}
print
"<div align='center'>"
;
print
"<button dojoType=
\"
dijit.form.Button
\"
onclick=
\"
dijit.byId('starredImportDlg').execute()
\"
>"
.
__
(
'Close this window'
)
.
"</button>"
;
print
"</div>"
;
if
(
!
$file
)
{
print
"<div align='center'>"
;
print
"<button dojoType=
\"
dijit.form.Button
\"
onclick=
\"
dijit.byId('starredImportDlg').execute()
\"
>"
.
__
(
'Close this window'
)
.
"</button>"
;
print
"</div>"
;
}
}
// expects ESCAPED data
private
function
create_article
(
$guid
,
$title
,
$updated
,
$link
,
$content
,
$author
,
$marked
)
{
$owner_uid
=
$_SESSION
[
"uid"
];
private
function
create_article
(
$owner_uid
,
$guid
,
$title
,
$updated
,
$link
,
$content
,
$author
,
$marked
)
{
if
(
!
$guid
)
$guid
=
sha1
(
$link
);
...
...
This diff is collapsed.
Click to expand it.
update.php
+
3
−
2
View file @
4cf0f9a9
...
...
@@ -37,7 +37,7 @@
"help"
);
foreach
(
$pluginhost
->
get_commands
()
as
$command
=>
$data
)
{
array_push
(
$longopts
,
$command
);
array_push
(
$longopts
,
$command
.
$data
[
"suffix"
]
);
}
$options
=
getopt
(
""
,
$longopts
);
...
...
@@ -79,7 +79,8 @@
print
"Plugin options:
\n
"
;
foreach
(
$pluginhost
->
get_commands
()
as
$command
=>
$data
)
{
printf
(
" --%-19s - %s
\n
"
,
"
$command
"
,
$data
[
"description"
]);
$args
=
$data
[
'arghelp'
];
printf
(
" --%-19s - %s
\n
"
,
"
$command
$args
"
,
$data
[
"description"
]);
}
return
;
...
...
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