Created
March 5, 2011 13:44
-
-
Save arjan/856361 to your computer and use it in GitHub Desktop.
Zotonic module to ping the Google blog pinger service whenever an article is updated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% @author Arjan Scherpenisse <[email protected]> | |
%% @copyright 2011 Arjan Scherpenisse | |
%% Date: 2011-03-05 | |
%% @doc Ping Google blog pinger service whenever an article is updated. | |
%% Copyright 2011 Arjan Scherpenisse | |
%% | |
%% Licensed under the Apache License, Version 2.0 (the "License"); | |
%% you may not use this file except in compliance with the License. | |
%% You may obtain a copy of the License at | |
%% | |
%% http://www.apache.org/licenses/LICENSE-2.0 | |
%% | |
%% Unless required by applicable law or agreed to in writing, software | |
%% distributed under the License is distributed on an "AS IS" BASIS, | |
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
%% See the License for the specific language governing permissions and | |
%% limitations under the License. | |
-module(mod_google_blog_pinger). | |
-author("Arjan Scherpenisse <[email protected]>"). | |
-mod_title("Google Blog Pinger"). | |
-mod_description("Pings the Google blog pinger service whenever an article is updated."). | |
-export([ | |
observe_rsc_pivot_done/2 | |
]). | |
-define(GOOGLE_PING_URL, "http://blogsearch.google.com/ping"). | |
-include("zotonic.hrl"). | |
observe_rsc_pivot_done({rsc_pivot_done, Id, IsA}, C) -> | |
Context = C#context{acl=undefined, user_id=undefined}, % make anonymous context | |
case lists:member(article, IsA) andalso m_rsc:is_visible(Id, Context) of | |
true -> | |
%% A publicly visible article; let's ping | |
spawn(fun() -> ok = ping(Context) end); | |
_ -> | |
ok | |
end. | |
%% @spec ping(Id, Context) -> ok | |
%% @doc Ping google with this article | |
ping(Context) -> | |
AtomUrl = case z_dispatcher:url_for(atom_feed, [{cat, article}], Context) of | |
undefined -> []; | |
U -> "&changesURL=" ++ z_utils:url_encode("http://" ++ m_site:get(hostname, Context) ++ z_convert:to_list(U)) | |
end, | |
Url = ?GOOGLE_PING_URL | |
++ "?name=" ++ z_utils:url_encode(z_convert:to_list(m_site:get(title, Context))) | |
++ "&url=" ++ z_utils:url_encode("http://" ++ m_site:get(hostname, Context)) | |
++ AtomUrl, | |
{ok, {{_Version, 200, _ReasonPhrase}, _Headers, _Body}} = | |
http:request(Url), | |
%%?DEBUG(Body), | |
?zInfo("Blog ping to Google OK.", Context), | |
ok. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For line 58: Warning: http:request/4 is deprecated and will be removed in R15B; use httpc:request/4