Exemplo n.º 1
0
 function widget($args, $instance)
 {
     $cache = wp_cache_get(__CLASS__);
     if (!is_array($cache)) {
         $cache = array();
     }
     if (empty($args['widget_id'])) {
         $args['widget_id'] = $this->id;
     }
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return;
     }
     ob_start();
     extract($args);
     $limit = !empty($instance['limit']) ? absint($instance['limit']) : 5;
     if (empty($limit)) {
         $limit = 5;
     }
     $title = !empty($instance['title']) ? $instance['title'] : false;
     $availableTypes = $this->_getAvailableTypes();
     if (empty($instance['type']) or !isset($availableTypes[$instance['type']])) {
         $tmp = array_keys($availableTypes);
         $instance['type'] = reset($tmp);
     }
     if ($title === false) {
         $title = $availableTypes[$instance['type']];
     }
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $config = xfac_option_getConfig();
     $threads = array();
     if (!empty($config) && !empty($instance['forumIds'])) {
         $forumId = implode(',', $instance['forumIds']);
         $extraParams = array('_xfac' => 'threads.php', 'limit' => $limit, 'sticky' => 0);
         switch ($instance['type']) {
             case 'recent':
                 $extraParams['order'] = 'thread_update_date_reverse';
                 break;
             case 'most_viewed':
                 $extraParams['order'] = 'thread_view_count_reverse';
                 break;
             case 'most_replied':
                 $extraParams['order'] = 'thread_post_count_reverse';
                 break;
             case 'new':
             default:
                 // this is the default order
                 // $extraParams['order'] = 'thread_create_date_reverse';
                 break;
         }
         $extraParams = http_build_query($extraParams);
         $results = xfac_api_getThreadsInForums($config, $forumId, '', $extraParams);
         if (!empty($results['threads'])) {
             $threads = $results['threads'];
         }
     }
     require xfac_template_locateTemplate('widget_threads.php');
     $cache[$args['widget_id']] = ob_get_flush();
     wp_cache_set(__CLASS__, $cache);
 }
Exemplo n.º 2
0
function xfac_syncPost_cron()
{
    $config = xfac_option_getConfig();
    if (empty($config)) {
        return;
    }
    $mappedTags = xfac_syncPost_getMappedTags();
    if (empty($mappedTags)) {
        return;
    }
    $forumFollowedSyncRecords = xfac_sync_getRecordsByProviderTypeAndSyncId('', 'forums/followed', 0);
    if (empty($forumFollowedSyncRecords) or time() - $forumFollowedSyncRecords[0]->sync_date > 86400) {
        xfac_update_option_tag_forum_mappings('xfac_tag_forum_mappings', null, get_option('xfac_tag_forum_mappings'));
    }
    $forumIds = array_keys($mappedTags);
    // sync sticky threads first
    $stickyThreads = xfac_api_getThreadsInForums($config, $forumIds, '', 'sticky=1');
    if (!empty($stickyThreads['threads'])) {
        xfac_syncPost_processThreads($config, $stickyThreads['threads'], $mappedTags);
    }
    // now start syncing normal threads
    $threads = xfac_api_getThreadsInForums($config, $forumIds);
    if (!empty($threads['threads'])) {
        xfac_syncPost_processThreads($config, $threads['threads'], $mappedTags);
    }
}