Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Guaraci WordPress Plugin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
Guaraci WordPress Plugin
Commits
1f153b4e
Commit
1f153b4e
authored
Apr 17, 2020
by
Isaque Melo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1
Wrap API with business rules
parent
b526d38e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
20 deletions
+28
-20
library/api.php
library/api.php
+19
-14
library/functions.php
library/functions.php
+2
-2
library/modules/facebook/index.php
library/modules/facebook/index.php
+7
-4
No files found.
library/api.php
View file @
1f153b4e
...
...
@@ -7,24 +7,29 @@ function get_facebook_shares( $data ) {
$access_token
=
'693244528146031|ae2b14c2d4f31b3434212179ee5550d8'
;
$post_id
=
$data
[
'post_id'
];
$response
=
wp_remote_get
(
add_query_arg
(
array
(
'id'
=>
urlencode
(
get_permalink
(
$post_id
)
),
//'id' => urlencode( 'https://www.google.com/' ),
'access_token'
=>
$access_token
,
'fields'
=>
'engagement'
),
'https://graph.facebook.com/v3.0/'
)
);
if
(
guaraci\need_share_update
(
$post_id
)
)
{
$response
=
wp_remote_get
(
add_query_arg
(
array
(
'id'
=>
urlencode
(
get_permalink
(
$post_id
)
),
//'id' => urlencode( 'https://www.google.com/' ),
'access_token'
=>
$access_token
,
'fields'
=>
'engagement'
),
'https://graph.facebook.com/v3.0/'
)
);
if
(
!
is_array
(
$response
)
&&
is_wp_error
(
$response
)
)
{
return
false
;
}
if
(
!
is_array
(
$response
)
&&
is_wp_error
(
$response
)
)
{
return
false
;
}
$body
=
json_decode
(
$response
[
'body'
]
);
$count
=
intval
(
$body
->
engagement
->
share_count
);
$body
=
json_decode
(
$response
[
'body'
]
);
$count
=
intval
(
$body
->
engagement
->
share_count
);
// Update post meta
guaraci\set_post_shares
(
$post_id
,
$count
);
}
else
{
$count
=
guaraci\get_post_shares
(
$post_id
);
}
// Update post meta
guaraci\set_post_shares
(
$post_id
,
$count
);
return
$count
;
}
...
...
library/functions.php
View file @
1f153b4e
...
...
@@ -106,7 +106,7 @@ function get_posts_ranking() {
$cache_key
=
'most_viewed_within_hour'
;
// use wp cache for optimization
$ids
=
get_transien
t
(
$cache_key
);
$ids
=
wp_cache_ge
t
(
$cache_key
);
if
(
$ids
===
false
)
{
$most_viewed
=
\AjaxPageviews
::
get_top_viewed
(
500
,
[
'post_type'
=>
'post'
,
'from'
=>
strtotime
(
'-24 hour'
)]);
...
...
@@ -116,7 +116,7 @@ function get_posts_ranking() {
array_push
(
$ids
,
$value
->
post_id
);
}
set_transient
(
$cache_key
,
$ids
,
120
);
wp_cache_add
(
$cache_key
,
$ids
,
120
);
}
var_dump
(
$ids
);
...
...
library/modules/facebook/index.php
View file @
1f153b4e
...
...
@@ -3,11 +3,14 @@ namespace guaraci;
function
need_share_update
(
$post_id
)
{
// se o metadado não existe ou se o metadado existe e foi atualizado a mais tempo do que o intervalo (F), retorna true
if
(
!
metadata_exists
(
'post'
,
$post_id
,
'shares'
))
{
// it has to be updated
if
(
!
metadata_exists
(
'post'
,
$post_id
,
'shares'
)
)
{
// the first time its called create the metadata for the next turn
update_post_meta
(
$post_id
,
'shares'
,
0
);
update_post_meta
(
$post_id
,
'updated_timestamp'
,
time
()
);
return
false
;
}
elseif
(
update_share_business_rule
(
$post_id
)
)
{
return
true
;
}
elseif
{
// define metadate
}
else
{
return
false
;
}
...
...
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