コード例 #1
0
/**
 * Save the projects returned from a portfolio fetch from behance
 */
function ikit_portfolio_remote_fetch_save($portfolios)
{
    // Purge portfolios as we will start from scratch
    ikit_delete_ikit_portfolios();
    global $wpdb;
    $project_table_name = $wpdb->prefix . IKIT_PORTFOLIO_PROJECT_TABLE_NAME;
    $owner_table_name = $wpdb->prefix . IKIT_PORTFOLIO_OWNER_TABLE_NAME;
    $project_owner_table_name = $wpdb->prefix . IKIT_PORTFOLIO_PROJECT_OWNER_TABLE_NAME;
    foreach ($portfolios as $portfolio) {
        $owner_id = intval($portfolio->aigaid);
        // Add owner
        $owner_data = array('id' => $owner_id, 'name' => $portfolio->name, 'url' => $portfolio->url, 'frame_url' => $portfolio->frameurl, 'aiga_chapter' => $portfolio->aigachapter);
        $rows_affected = $wpdb->insert($owner_table_name, $owner_data);
        // Each owner has an associated WordPress post
        $associated_post = array('post_title' => (string) $portfolio->name, 'post_type' => IKIT_POST_TYPE_IKIT_PORTFOLIO, 'post_status' => 'publish', 'post_date' => current_time('mysql'));
        $new_associated_post_id = wp_insert_post($associated_post);
        if ($new_associated_post_id > 0) {
            // Add the event id to link this post with the project
            add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_PORTFOLIO_ID, $owner_id, true);
            add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_PORTFOLIO_CHAPTER, (string) $portfolio->aigachapter, true);
        }
        $projects = $portfolio->projects->project;
        foreach ($projects as $project) {
            // Add project
            $project_id = intval($project->id);
            $project_data = array('id' => $project_id, 'title' => $project->title, 'url' => $project->url, 'cover_image_url' => $project->coverimage, 'published_date' => date('Y-m-d H:i:s', strtotime($project->pubDate)));
            $rows_affected = $wpdb->insert($project_table_name, $project_data);
            // Add project owner relationship
            $project_owner_data = array('project_id' => $project_id, 'owner_id' => $owner_id);
            $rows_affected = $wpdb->insert($project_owner_table_name, $project_owner_data);
        }
    }
}
コード例 #2
0
function ikit_menu_control_panel_process_request()
{
    // Handle form submission
    $action = null;
    if (isset($_POST['action'])) {
        $action = $_POST['action'];
    }
    // Pull etouches events
    if ($action == 'force_pull_etouches_events') {
        ikit_event_etouches_remote_fetch();
    }
    // Pull Eventbrite events
    if ($action == 'force_pull_eventbrite_events') {
        try {
            ikit_event_eventbrite_remote_fetch();
        } catch (Exception $e) {
            // Display admin error if problem fetching
            global $g_admin_notices;
            array_push($g_admin_notices, '<div class="error">Error during force pull Eventbrite events: ' . $e->getMessage() . '</div>');
        }
    }
    // Delete etouches events
    if ($action == 'force_purge_etouches_events') {
        ikit_delete_ikit_events(IKIT_EVENT_SERVICE_ETOUCHES);
    }
    // Delete Eventbrite events
    if ($action == 'force_purge_eventbrite_events') {
        ikit_delete_ikit_events(IKIT_EVENT_SERVICE_EVENTBRITE);
    }
    // Delete all jobs
    if ($action == 'force_purge_jobs') {
        ikit_delete_ikit_jobs();
    }
    // Delete all portfolios
    if ($action == 'force_purge_portfolios') {
        ikit_delete_ikit_portfolios();
    }
}