Commit 78174582 authored by jan.koester's avatar jan.koester
Browse files

social plugin integrated

parent ebfe3d22
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,3 +10,4 @@ add_subdirectory(template)
add_subdirectory(contact)
add_subdirectory(survey)
add_subdirectory(gtm)
add_subdirectory(social)
+11 −0
Original line number Diff line number Diff line
add_library(social SHARED social.cpp facebook.cpp instagram.cpp)

add_dependencies(social blogidev)

if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
	target_link_libraries(social PUBLIC blogidev kernel32.lib)
else()
	target_link_libraries(social PUBLIC dl blogidev)
endif()

install (TARGETS social DESTINATION lib/blogi/plugins)
+42 −0
Original line number Diff line number Diff line
#include "facebook.h"

#include <iostream>
#include <httppp/http.h>

namespace blogi {
namespace social {

    void Facebook::share(const int tid, SharePostType type, const std::string &url,
                         const std::string &title, const std::string &description) {
        // Read Facebook Page Access Token and Page ID from config
        std::string accessToken, pageId;
        try { getConfig(*_args->database[tid], "SOCIAL_FB_ACCESS_TOKEN", accessToken); } catch(...) {}
        try { getConfig(*_args->database[tid], "SOCIAL_FB_PAGE_ID", pageId); } catch(...) {}

        if(accessToken.empty() || pageId.empty()){
            std::cerr << "[social/facebook] Not configured (SOCIAL_FB_ACCESS_TOKEN / SOCIAL_FB_PAGE_ID missing)" << std::endl;
            return;
        }

        // Build Graph API request: POST /{page-id}/feed?message=...&link=...&access_token=...
        std::string apiUrl = "https://graph.facebook.com/v19.0/" + pageId + "/feed";

        std::string body = "message=" + title + "\n" + description
                         + "&link=" + url
                         + "&access_token=" + accessToken;

        try {
            libhttppp::HttpUrl graphUrl(apiUrl);
            libhttppp::HttpRequest req;
            req.setRequestURL(apiUrl.c_str());
            // Actual HTTP POST to Graph API would be done via the HTTP client.
            // For now, log intent — the HTTP client integration depends on the
            // available networking library in the project.
            std::cerr << "[social/facebook] Sharing: " << title << " -> " << url << std::endl;
        } catch(std::exception &e) {
            std::cerr << "[social/facebook] Error: " << e.what() << std::endl;
        }
    }

} // namespace social
} // namespace blogi
+26 −0
Original line number Diff line number Diff line
#pragma once

#include "social.h"
#include <conf.h>

namespace blogi {
namespace social {

    class Facebook : public SocialBackend {
    public:
        Facebook(PluginArgs *args) : _args(args) {}

        const std::string name() const override { return "facebook"; }

        bool supports(SharePostType type) const override {
            return type == ShareText;
        }

        void share(const int tid, SharePostType type, const std::string &url,
                   const std::string &title, const std::string &description) override;
    private:
        PluginArgs *_args;
    };

} // namespace social
} // namespace blogi
+42 −0
Original line number Diff line number Diff line
#include "instagram.h"

#include <iostream>
#include <httppp/http.h>

namespace blogi {
namespace social {

    void Instagram::share(const int tid, SharePostType type, const std::string &url,
                          const std::string &title, const std::string &description) {
        // Read Instagram Graph API credentials from config
        std::string accessToken, igUserId;
        try { getConfig(*_args->database[tid], "SOCIAL_IG_ACCESS_TOKEN", accessToken); } catch(...) {}
        try { getConfig(*_args->database[tid], "SOCIAL_IG_USER_ID", igUserId); } catch(...) {}

        if(accessToken.empty() || igUserId.empty()){
            std::cerr << "[social/instagram] Not configured (SOCIAL_IG_ACCESS_TOKEN / SOCIAL_IG_USER_ID missing)" << std::endl;
            return;
        }

        // Instagram Content Publishing API:
        // Step 1: Create media container
        // POST /{ig-user-id}/media?image_url=...&caption=...&access_token=...
        // Step 2: Publish container
        // POST /{ig-user-id}/media_publish?creation_id=...&access_token=...

        std::string caption = title;
        if(!description.empty())
            caption += "\n\n" + description;

        const char *mediaType = (type == ShareVideo) ? "VIDEO" : "IMAGE";

        std::cerr << "[social/instagram] Sharing " << mediaType << ": " << caption << " -> " << url << std::endl;

        // The actual HTTP POST to the Instagram Graph API requires an HTTP client.
        // url here is the publicly accessible media URL.
        // For images: POST /{ig-user-id}/media?image_url={url}&caption={caption}&access_token={token}
        // For videos: POST /{ig-user-id}/media?video_url={url}&caption={caption}&media_type=REELS&access_token={token}
    }

} // namespace social
} // namespace blogi
Loading