示例#1
0
 private function makeSummary()
 {
     zf_debug('Normalizing summary for ' . $this->data['id'], DBG_FEED);
     if (strlen($this->data['summary']) == 0) {
         $this->data['summary'] = $this->data['description'];
     }
     if (strlen($this->data['summary']) > 0) {
         $strsum = strip_tags($this->data['summary']);
         zf_debug(strlen($strsum) . ' chars in stripped summary, unstripped: ' . strlen($this->data['summary']), DBG_FEED);
         //strip out inline css and simplify style tags
         $search = array('#<(strong|b)[^>]*>(.*?)</(strong|b)>#isu', '#<(em|i)[^>]*>(.*?)</(em|i)>#isu', '#<u[^>]*>(.*?)</u>#isu');
         $replace = array('<b>$2</b>', '<i>$2</i>', '<u>$1</u>');
         $strsum = preg_replace($search, $replace, $strsum);
         if (strlen($strsum) > ZF_MAX_SUMMARY_LENGTH) {
             zf_debug('truncating summary', DBG_FEED);
             $strsum = substr($strsum, 0, ZF_SUMMARY_TRUNCATED_LENGTH);
             // don't chop words. chop at the last space character found
             $lastspace = strrpos($strsum, ' ');
             $strsum = substr($strsum, 0, $lastspace) . '...';
             $this->data['summary'] = $strsum;
         }
     }
 }
示例#2
0
 public static function createFromFlatArray($source, $item, $isNewSpot = 0xffffffff)
 {
     zf_debug('processing cached item ' . $item['id'] . ' source ' . $source->id, DBG_ITEM | DBG_FEED);
     if (ZF_DEBUG & DBG_ITEM) {
         var_dump($item);
     }
     $feedItem = new NewsItem($source);
     zf_debug("new spot TS: {$isNewSpot} impressed on: " . $item['ts_impress'], DBG_ITEM | DBG_FEED);
     $feedItem->isNew = $isNewSpot < $item['ts_impress'];
     $enclosures = json_decode($item['enclosures']);
     /* remove fields we dont need anymore */
     unset($item['ts_impress']);
     unset($item['enclosures']);
     unset($item['source_id']);
     foreach ($item as $key => $value) {
         if (!is_array($value)) {
             $feedItem->{$key} = $value;
         }
     }
     if (is_array($enclosures)) {
         foreach ($enclosures as $enc) {
             $newenc = new Enclosure();
             foreach ($enc as $key => $value) {
                 $newenc->{$key} = $value;
             }
             /*				$newenc->link = $enc['link'];
             				$newenc->length = $enc['length'];
             				$newenc->type = $enc['type'];*/
             array_push($feedItem->enclosures, $newenc);
         }
     }
     zf_debug('cached item after processing ' . $feedItem->id, DBG_FEED | DBG_ITEM);
     if (ZF_DEBUG & DBG_ITEM) {
         var_dump($feedItem);
     }
     return $feedItem;
 }
示例#3
0
 private function _sanitize()
 {
     $nextPos = $this->getNextPosition();
     foreach ($this->subscriptions as $i => $sub) {
         if (!($sub->position > 0 && is_numeric($sub->position))) {
             zf_debug('fixing position: ' . $sub->title . ' (' . $sub->position . ') to ' . $nextPos, DBG_OPML);
             $sub->position = $nextPos;
             $nextPos++;
         }
     }
 }
示例#4
0
 public function load()
 {
     $this->_loadFile();
     /* here are our template parts */
     $this->pageHeader = $this->_extractSection('templateHeader');
     $this->header = $this->_extractSection('header', '', true);
     $this->footer = $this->_extractSection('footer', '', true);
     $this->channel = $this->_extractSection('channel');
     $this->channelFooter = $this->_extractSection('channelFooter', '', true);
     $this->news = $this->_extractSection('news');
     $this->newsByDate = $this->_extractSection('newsByDate', 'news');
     $this->newsDay = $this->_extractSection('newsDay', '', true);
     $this->newsDayFooter = $this->_extractSection('newsDayFooter', 'channelFooter', true);
     $this->article = $this->_extractSection('article');
     zf_debug("template loaded", DBG_RENDER);
     // unset to free memory
     unset($this->_html);
 }
示例#5
0
 protected function updateAllParallel($subscriptions)
 {
     zf_debugRuntime("before feeds parallel update");
     $urls = array();
     foreach ($subscriptions as $sub) {
         $url = ZF_URL . '/pub/index.php?q=force-refresh&id=' . $sub->source->id;
         $urls[] = $url;
     }
     // Request all feed items in parallel (if supported)
     $http = new HumbleHttpAgent();
     $http->userAgentDefault = HumbleHttpAgent::UA_PHP;
     zf_debug('fetching all ' . sizeof($urls) . ' feeds', DBG_FEED);
     $http->fetchAll($urls);
     foreach ($urls as $url) {
         zf_debug('going after ' . $url, DBG_FEED);
         if ($url && ($response = $http->get($url, true)) && ($response['status_code'] < 300 || $response['status_code'] > 400)) {
             $effective_url = $response['effective_url'];
             /*zf_debug('response: '. $response['body'], DBG_FEED);
             		if(DBG_FEED & ZF_DEBUG) var_dump($response);*/
         }
     }
     zf_debugRuntime("End of parallel update");
 }
示例#6
0
 public function recordItemFetchTime($itemIds, $ts = -1)
 {
     if ($ts == -1) {
         $ts = time();
     }
     $entries = $this->db->update('items', array('ts_fetch' => $ts), array('id' => $itemIds));
     if (ZF_DEBUG & DBG_DB) {
         var_dump($this->db->last_query());
         var_dump($this->db->error());
         zf_debug("{$entries} items updated");
     }
 }
示例#7
0
function zf_debugRuntime($location)
{
    if (ZF_DEBUG & DBG_RUNTIME) {
        global $zf_debugData;
        $zf_debugData['clock'][] = microtime();
        $count = count($zf_debugData['clock']);
        // take previous element
        $entry = explode(' ', $zf_debugData['clock'][$count - 2]);
        $startVal = (double) $entry[0] + (double) $entry[1];
        $entry = explode(' ', $zf_debugData['clock'][$count - 1]);
        $runVal = (double) $entry[0] + (double) $entry[1] - (double) $startVal;
        $part1 = "[{$location}] Run time since last check: " . $runVal . " sec.";
        // take first element of the debug array
        $entry = explode(' ', $zf_debugData['clock'][0]);
        $startVal = (double) $entry[0] + (double) $entry[1];
        $entry = explode(' ', $zf_debugData['clock'][$count - 1]);
        $runVal2 = (double) $entry[0] + (double) $entry[1] - (double) $startVal;
        zf_debug($part1 . " (total: " . $runVal2 . " sec.)");
        // try to use PHP build in function
        if (function_exists('memory_get_usage')) {
            zf_debug("Memory: using " . memory_get_usage() . " bytes");
        }
        if (function_exists('getrusage')) {
            $dat = getrusage();
            $utime_after = $dat["ru_utime.tv_sec"] . $dat["ru_utime.tv_usec"];
            $stime_after = $dat["ru_stime.tv_sec"] . $dat["ru_stime.tv_usec"];
            $utime_elapsed = $utime_after - $zf_debugData['utime_before'];
            $stime_elapsed = $stime_after - $zf_debugData['stime_before'];
            zf_debug("Elapsed user time: {$utime_elapsed} microseconds");
            zf_debug("Elapsed system time: {$stime_elapsed} microseconds");
        }
    }
}
示例#8
0
 private function buildLimiterParam($trim)
 {
     zf_debug("handling trim string {$trim}", DBG_AGGR);
     $result = array();
     if (preg_match("/([0-9]+)(.*)/", $trim, $matches)) {
         $type = $matches[2];
         $size = $matches[1];
         // get timestamp we don't want to go further
         switch ($type) {
             case 'hours':
                 // earliest is the timestamp before which we should ignore news
                 $result['sincePubdate'] = time() - 3600 * $size;
                 break;
             case 'days':
                 // earliest is the timestamp before which we should ignore news
                 // get timestamp of today at 0h00
                 $todayts = strtotime(date("F j, Y"));
                 // substract x-1 times 3600*24 seconds from that
                 // x-1 because the current day counts, in the last x days
                 $result['sincePubdate'] = $todayts - 3600 * 24 * ($size - 1);
                 break;
             case 'news':
                 $result['max'] = $size;
                 break;
         }
     }
     return $result;
 }
示例#9
0
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
/* template for the admin page */
/* initialization part */
require_once 'init.php';
require_once 'includes/adminfuncs.php';
$zfaction = param('zfaction', ZF_DEFAULT_ADMIN_VIEW);
zf_debug('zfaction is ' . $zfaction);
// another quick thing to fix later.
// if zfaction default is subscriptions, we never get to
// see the article page when clicked from the feeds page
$q = param('q', '');
if (strlen($q) > 0) {
    $zfaction = 'feeds';
}
zfLogin();
//dirty... treat async calls first to avoid page header etc
switch ($zfaction) {
    case 'store':
        Header('Content-Type: text/html; charset=' . ZF_ENCODING);
        $storage = SubscriptionStorage::getInstance();
        $id = $_POST['id'];
        $sub = $storage->getSubscription($id);
示例#10
0
文件: view.php 项目: mm999/zebrafeeds
 protected function renderNewsItems($feed, $params)
 {
     zf_debug('Rendering Newsitems of ' . (isset($feed->subscriptionId) ? $feed->subscriptionId : 'aggregated feed') . ' in TemplateView', DBG_RENDER);
     $currentDay = '';
     //$today = date('m.d.Y');
     //$yesterday = date('m.d.Y',strtotime("-1 day"));
     //foreach item
     $itemsList =& $feed->items;
     zf_debug(sizeof($itemsList) . ' items to render', DBG_RENDER);
     $groupbyday = $params['groupbyday'];
     if ($groupbyday) {
         zf_debug("group by day is set", DBG_RENDER);
     }
     foreach ($itemsList as $item) {
         /* two ways of rendering:
         			- group by day, we use a special template part, and separate each day
         			- normal, use the regular news template
         			 */
         if ($groupbyday) {
             $day = zf_transcode(strftime(ZF_DATEFORMAT, date($item->pubdate)));
             /*
             				 * non locale-friendly way...
             				 $day_std = date('m.d.Y', $item['date_timestamp']);
             
             				if ($day_std == $today) {
             					$day = "Today";
             			}
             			if ($day_std == $yesterday) {
             				$day = "Yesterday";
             			}*/
             if ($currentDay != $day && ZF_GROUP_BY_DAY == 'yes') {
                 // if not the first time that we enter here
                 if ($currentDay != "") {
                     // terminate properly our day and start a new one
                     $this->template->printDayFooter($currentDay);
                 }
                 $currentDay = $day;
                 //echo zf_formatTemplate(array(), $day, array(), $template->newsDay, false);
                 $this->template->printDay($currentDay);
             }
             zf_debug("print news by date", DBG_RENDER);
             $this->template->printNewsByDate($item);
         } else {
             zf_debug("print news", DBG_RENDER);
             $this->template->printNews($item);
         }
     }
     // end foreach
     if ($params['groupbyday'] && ZF_GROUP_BY_DAY == 'yes') {
         // terminate the last day we used
         $this->template->printDayFooter($currentDay);
     }
 }