2009-08-03 16:42:04 +04:00
< ? php
/*
* This file is part of FEED ON FEEDS - http :// feedonfeeds . com /
*
* fof - main . php - initializes FoF , and contains functions used from other scripts
*
2014-11-01 15:21:34 +03:00
* Copyright ( C ) 2004 - 2007 Stephen Minutillo steve @ minutillo . com http :// minutillo . com / steve /
* ( C ) 2009 - 2014 Vitaliy Filippov vitalif @ mail . ru http :// yourcmc . ru / wiki /
2009-08-03 16:42:04 +04:00
*
* Distributed under the GPL - see LICENSE
*
*/
fof_repair_drain_bamage ();
if ( ! file_exists ( dirname ( __FILE__ ) . '/fof-config.php' ) )
{
echo " You will first need to create a fof-config.php file. Please copy fof-config-sample.php to fof-config.php and then update the values to match your database settings. " ;
die ();
}
2012-03-03 00:31:25 +04:00
require_once ( 'fof-config.php' );
require_once ( 'fof-db.php' );
require_once ( 'classes/fof-prefs.php' );
require_once ( 'simplepie/simplepie.php' );
2011-07-21 15:25:55 +04:00
#if (file_exists(dirname(__FILE__).'/login-external.php'))
# require_once(dirname(__FILE__).'/login-external.php');
2009-08-03 16:42:04 +04:00
2012-03-03 00:31:25 +04:00
$fof_item_prefilters = array ();
$fof_tag_prefilters = array ();
2009-08-03 16:42:04 +04:00
fof_db_connect ();
2014-12-09 01:29:47 +03:00
if ( empty ( $fof_installer ))
2009-08-03 16:42:04 +04:00
{
2014-12-09 01:29:47 +03:00
if ( empty ( $fof_no_login ))
2009-08-03 16:42:04 +04:00
{
require_user ();
2012-12-31 14:24:42 +04:00
$fof_prefs_obj = FoF_Prefs :: instance ();
2009-08-03 16:42:04 +04:00
}
else
{
$fof_user_id = 1 ;
2012-12-31 14:24:42 +04:00
$fof_prefs_obj = FoF_Prefs :: instance ();
2009-08-03 16:42:04 +04:00
}
ob_start ();
fof_init_plugins ();
ob_end_clean ();
}
function fof_set_content_type ()
{
static $set ;
if ( ! $set )
{
header ( " Content-Type: text/html; charset=utf-8 " );
$set = true ;
}
}
function fof_log ( $message , $topic = " debug " )
{
global $fof_prefs_obj ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( ! $fof_prefs_obj ) return ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$p = $fof_prefs_obj -> admin_prefs ;
if ( ! $p [ 'logging' ]) return ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
static $log ;
if ( ! isset ( $log )) $log = @ fopen ( " fof.log " , 'a' );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( ! $log ) return ;
2009-10-26 16:16:15 +03:00
$message = str_replace ( " \n " , " \\ n " , $message );
$message = str_replace ( " \r " , " \\ r " , $message );
2009-08-03 16:42:04 +04:00
fwrite ( $log , date ( 'r' ) . " [ $topic ] $message\n " );
}
function require_user ()
{
2011-07-21 15:25:55 +04:00
// FIXME Пилять! Да это же по безопасности, как HTTP Basic авторизация! :-(
2009-08-03 16:42:04 +04:00
$user_name = $_COOKIE [ " user_name " ];
$user_password_hash = $_COOKIE [ " user_password_hash " ];
2009-10-26 16:16:15 +03:00
2011-07-21 15:25:55 +04:00
if ( ! $user_name || ! $user_password_hash || ! fof_authenticate ( $user_name , $user_password_hash ))
2009-08-03 16:42:04 +04:00
{
2011-08-12 00:25:43 +04:00
if ( ! function_exists ( 'fof_require_user_hook' ) ||
2011-07-21 15:25:55 +04:00
! fof_require_user_hook ())
{
header ( " Location: login.php " );
exit ;
}
2009-08-03 16:42:04 +04:00
}
}
function fof_authenticate ( $user_name , $user_password_hash )
{
global $fof_user_name ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( fof_db_authenticate ( $user_name , $user_password_hash ))
{
setcookie ( " user_name " , $fof_user_name , time () + 60 * 60 * 24 * 365 * 10 );
setcookie ( " user_password_hash " , $user_password_hash , time () + 60 * 60 * 24 * 365 * 10 );
return true ;
}
}
function fof_logout ()
{
setcookie ( " user_name " , " " , time () );
setcookie ( " user_password_hash " , " " , time () );
2011-07-21 15:25:55 +04:00
setcookie ( " logged_out " , " 1 " , time () + 300 );
2009-08-03 16:42:04 +04:00
}
function fof_current_user ()
{
global $fof_user_id ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
return $fof_user_id ;
}
function fof_username ()
{
global $fof_user_name ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
return $fof_user_name ;
}
function fof_get_users ()
{
return fof_db_get_users ();
}
function fof_prefs ()
2009-10-26 16:16:15 +03:00
{
2012-12-31 14:24:42 +04:00
$p = FoF_Prefs :: instance ();
2009-08-03 16:42:04 +04:00
return $p -> prefs ;
}
function fof_is_admin ()
{
global $fof_user_level ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
return $fof_user_level == " admin " ;
}
function fof_get_unread_count ( $user_id )
{
return fof_db_get_unread_count ( $user_id );
}
function fof_get_tags ( $user_id )
{
$tags = array ();
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$result = fof_db_get_tags ( $user_id );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$counts = fof_db_get_tag_unread ( $user_id );
2009-10-26 16:16:15 +03:00
2014-11-01 16:12:13 +03:00
foreach ( $result as $row )
2009-08-03 16:42:04 +04:00
{
if ( isset ( $counts [ $row [ 'tag_id' ]]))
2009-12-07 01:12:15 +03:00
$row [ 'unread' ] = $counts [ $row [ 'tag_id' ]];
2009-08-03 16:42:04 +04:00
else
2009-12-07 01:12:15 +03:00
$row [ 'unread' ] = 0 ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$tags [] = $row ;
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
return $tags ;
}
function fof_get_item_tags ( $user_id , $item_id )
{
2009-10-26 16:16:15 +03:00
$result = fof_db_get_item_tags ( $user_id , $item_id );
$tags = array ();
while ( $row = fof_db_get_row ( $result ))
{
$tags [] = $row [ 'tag_name' ];
2009-08-03 16:42:04 +04:00
}
2009-10-26 16:16:15 +03:00
return $tags ;
2009-08-03 16:42:04 +04:00
}
function fof_tag_feed ( $user_id , $feed_id , $tag )
{
$tag_id = fof_db_get_tag_by_name ( $user_id , $tag );
2014-11-01 15:21:34 +03:00
if ( ! $tag_id )
2009-08-03 16:42:04 +04:00
{
$tag_id = fof_db_create_tag ( $user_id , $tag );
}
fof_db_tag_feed ( $user_id , $feed_id , $tag_id );
}
function fof_untag_feed ( $user_id , $feed_id , $tag )
{
$tag_id = fof_db_get_tag_by_name ( $user_id , $tag );
2014-11-01 15:21:34 +03:00
if ( $tag_id )
2009-08-03 16:42:04 +04:00
{
2014-11-01 15:21:34 +03:00
fof_db_untag_feed ( $user_id , $feed_id , $tag_id );
2009-08-03 16:42:04 +04:00
}
}
2014-11-01 15:21:34 +03:00
function fof_tag_item ( $user_id , $item_id , $tags )
2009-08-03 16:42:04 +04:00
{
2014-11-01 15:21:34 +03:00
foreach (( array ) $tags as $tag )
2009-10-26 16:16:15 +03:00
{
$tag_id = fof_db_get_tag_by_name ( $user_id , $tag );
2014-11-01 15:21:34 +03:00
if ( ! $tag_id )
2009-10-26 16:16:15 +03:00
{
2014-11-01 15:21:34 +03:00
$tag_id = fof_db_create_tag ( $user_id , $tag );
2009-10-26 16:16:15 +03:00
}
fof_db_tag_items ( $user_id , $tag_id , $item_id );
}
2009-08-03 16:42:04 +04:00
}
function fof_untag_item ( $user_id , $item_id , $tag )
{
2009-10-26 16:16:15 +03:00
$tag_id = fof_db_get_tag_by_name ( $user_id , $tag );
fof_db_untag_items ( $user_id , $tag_id , $item_id );
2009-08-03 16:42:04 +04:00
}
function fof_untag ( $user_id , $tag )
{
$tag_id = fof_db_get_tag_by_name ( $user_id , $tag );
$result = fof_db_get_items ( $user_id , $feed_id , $tag , NULL , NULL );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
foreach ( $result as $r )
{
$items [] = $r [ 'item_id' ];
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
fof_db_untag_items ( $user_id , $tag_id , $items );
}
function fof_nice_time_stamp ( $age )
{
2009-10-26 16:16:15 +03:00
$age = time () - $age ;
if ( $age == 0 )
{
$agestr = " never " ;
$agestrabbr = " ∞ " ;
}
else
{
$seconds = $age % 60 ;
$minutes = $age / 60 % 60 ;
$hours = $age / 60 / 60 % 24 ;
$days = floor ( $age / 60 / 60 / 24 );
if ( $seconds )
{
2009-08-03 16:42:04 +04:00
$agestr = " $seconds second " ;
if ( $seconds != 1 ) $agestr .= " s " ;
$agestr .= " ago " ;
$agestrabbr = $seconds . " s " ;
2009-10-26 16:16:15 +03:00
}
2009-08-03 16:42:04 +04:00
2009-10-26 16:16:15 +03:00
if ( $minutes )
{
2009-08-03 16:42:04 +04:00
$agestr = " $minutes minute " ;
if ( $minutes != 1 ) $agestr .= " s " ;
$agestr .= " ago " ;
$agestrabbr = $minutes . " m " ;
2009-10-26 16:16:15 +03:00
}
2009-08-03 16:42:04 +04:00
2009-10-26 16:16:15 +03:00
if ( $hours )
{
2009-08-03 16:42:04 +04:00
$agestr = " $hours hour " ;
if ( $hours != 1 ) $agestr .= " s " ;
$agestr .= " ago " ;
$agestrabbr = $hours . " h " ;
2009-10-26 16:16:15 +03:00
}
2009-08-03 16:42:04 +04:00
2009-10-26 16:16:15 +03:00
if ( $days )
{
2009-08-03 16:42:04 +04:00
$agestr = " $days day " ;
if ( $days != 1 ) $agestr .= " s " ;
$agestr .= " ago " ;
$agestrabbr = $days . " d " ;
2009-10-26 16:16:15 +03:00
}
}
return array ( $agestr , $agestrabbr );
2009-08-03 16:42:04 +04:00
}
function fof_get_feeds ( $user_id , $order = 'feed_title' , $direction = 'asc' )
{
2009-10-26 16:16:15 +03:00
$feeds = array ();
$result = fof_db_get_subscriptions ( $user_id );
2014-12-09 01:29:47 +03:00
while ( $row = fof_db_get_row ( $result ))
2009-10-26 16:16:15 +03:00
{
$age = $row [ 'feed_cache_date' ];
list ( $agestr , $agestrabbr ) = fof_nice_time_stamp ( $age );
2014-12-09 01:29:47 +03:00
$feeds [ $row [ 'feed_id' ]] = array (
'prefs' => unserialize ( $row [ 'subscription_prefs' ]),
'feed_id' => $row [ 'feed_id' ],
'feed_url' => $row [ 'feed_url' ],
'feed_title' => $row [ 'feed_title' ],
'feed_link' => $row [ 'feed_link' ],
'feed_description' => $row [ 'feed_description' ],
'feed_image' => $row [ 'feed_image' ],
'feed_age' => $age ,
'agestr' => $agestr ,
'agestrabbr' => $agestrabbr ,
'feed_items' => 0 ,
'feed_read' => 0 ,
'feed_unread' => 0 ,
'feed_starred' => 0 ,
'max_date' => NULL ,
'lateststr' => '' ,
'lateststrabbr' => '' ,
);
2009-10-26 16:16:15 +03:00
}
$tags = fof_db_get_tag_id_map ();
2014-12-09 01:29:47 +03:00
foreach ( $feeds as & $feed )
2009-10-26 16:16:15 +03:00
{
2014-12-09 01:29:47 +03:00
$feed [ 'tags' ] = array ();
if ( is_array ( $feed [ 'prefs' ][ 'tags' ]))
2009-10-26 16:16:15 +03:00
{
2014-12-09 01:29:47 +03:00
foreach ( $feed [ 'prefs' ][ 'tags' ] as $tag )
2009-10-26 16:16:15 +03:00
{
2014-12-09 01:29:47 +03:00
$feed [ 'tags' ][] = $tags [ $tag ];
2009-10-26 16:16:15 +03:00
}
}
}
$result = fof_db_get_item_count ( $user_id );
2014-12-09 01:29:47 +03:00
while ( $row = fof_db_get_row ( $result ))
2009-10-26 16:16:15 +03:00
{
2014-12-09 01:29:47 +03:00
$feeds [ $row [ 'id' ]][ 'feed_items' ] = $row [ 'count' ];
$feeds [ $row [ 'id' ]][ 'feed_read' ] = $row [ 'count' ];
2009-10-26 16:16:15 +03:00
}
2014-11-01 15:21:34 +03:00
$result = fof_db_get_tagged_item_count ( $user_id , 1 );
2014-12-09 01:29:47 +03:00
while ( $row = fof_db_get_row ( $result ))
2009-10-26 16:16:15 +03:00
{
2014-12-09 01:29:47 +03:00
$feeds [ $row [ 'id' ]][ 'feed_unread' ] = $row [ 'count' ];
2009-10-26 16:16:15 +03:00
}
2014-11-01 15:21:34 +03:00
$result = fof_db_get_tagged_item_count ( $user_id , 2 );
2014-12-09 01:29:47 +03:00
while ( $row = fof_db_get_row ( $result ))
2009-10-26 16:16:15 +03:00
{
2014-12-09 01:29:47 +03:00
$feeds [ $row [ 'id' ]][ 'feed_starred' ] = $row [ 'count' ];
2009-10-26 16:16:15 +03:00
}
$result = fof_db_get_latest_item_age ( $user_id );
2014-12-09 01:29:47 +03:00
while ( $row = fof_db_get_row ( $result ))
2009-10-26 16:16:15 +03:00
{
2014-12-09 01:29:47 +03:00
if ( ! isset ( $feeds [ $row [ 'id' ]]))
2009-10-26 16:16:15 +03:00
{
2014-12-09 01:29:47 +03:00
var_dump ( $row );
die ();
2009-10-26 16:16:15 +03:00
}
2014-12-09 01:29:47 +03:00
$feeds [ $row [ 'id' ]][ 'max_date' ] = $row [ 'max_date' ];
list ( $agestr , $agestrabbr ) = fof_nice_time_stamp ( $row [ 'max_date' ]);
$feeds [ $row [ 'id' ]][ 'lateststr' ] = $agestr ;
$feeds [ $row [ 'id' ]][ 'lateststrabbr' ] = $agestrabbr ;
2009-10-26 16:16:15 +03:00
}
$feeds = fof_multi_sort ( $feeds , $order , $direction != " asc " );
return $feeds ;
2009-08-03 16:42:04 +04:00
}
2010-01-25 20:30:38 +03:00
function fof_feed_title ( $feed , $prefs = NULL )
{
2014-12-09 16:07:00 +03:00
if ( ! $prefs && ! empty ( $feed [ 'prefs' ]))
{
2010-01-25 20:30:38 +03:00
$prefs = $feed [ 'prefs' ];
2014-12-09 16:07:00 +03:00
}
2010-01-25 20:30:38 +03:00
if ( ! $prefs )
2014-12-09 16:07:00 +03:00
{
2010-01-25 20:30:38 +03:00
$prefs = fof_db_get_subscription_prefs ( fof_current_user (), $feed [ 'feed_id' ]);
2014-12-09 16:07:00 +03:00
}
2014-12-09 01:29:47 +03:00
$t = ! empty ( $prefs [ 'feed_title' ]) ? $prefs [ 'feed_title' ] : $feed [ 'feed_title' ];
2010-01-25 20:30:38 +03:00
return $t ;
}
2014-12-09 16:07:00 +03:00
function fof_view_title ( $feed = NULL , $what = " new " , $when = NULL , $start = NULL , $limit = NULL , $search = NULL )
2009-08-03 16:42:04 +04:00
{
$prefs = fof_prefs ();
$title = " feed on feeds " ;
2009-10-26 16:16:15 +03:00
2014-12-09 16:07:00 +03:00
if ( ! is_null ( $when ) && $when != " " )
2009-08-03 16:42:04 +04:00
{
2010-01-25 20:30:38 +03:00
$title .= ' - ' . $when ;
2009-08-03 16:42:04 +04:00
}
2010-01-25 20:30:38 +03:00
if ( ! is_null ( $feed ) && $feed != " " &&
( $r = fof_db_get_feed_by_id ( $feed )))
2009-08-03 16:42:04 +04:00
{
2010-01-25 20:30:38 +03:00
$title .= ' - ' . htmlspecialchars ( fof_feed_title ( $r ), ENT_QUOTES );
2009-08-03 16:42:04 +04:00
}
2010-01-25 20:30:38 +03:00
2009-08-03 16:42:04 +04:00
if ( is_numeric ( $start ))
{
if ( ! is_numeric ( $limit )) $limit = $prefs [ " howmany " ];
$title .= " - items $start to " . ( $start + $limit );
}
2010-01-25 20:30:38 +03:00
2009-08-03 16:42:04 +04:00
if ( $what != " all " )
{
2010-01-25 20:30:38 +03:00
$wh = array ();
$new = '' ;
foreach ( explode ( ',' , $what ) as $t )
{
if ( $t == 'unread' )
$new = ' new' ;
else
$wh [] = $t ;
}
$title .= ' -' . $new . ' items' ;
if ( count ( $wh ))
$title .= ' tagged ' . implode ( ',' , $wh );
2009-08-03 16:42:04 +04:00
}
else
$title .= ' - all items' ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( isset ( $search ))
{
$title .= " - <a href='javascript:toggle_highlight()'>matching <i class='highlight'> $search </i></a> " ;
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
return $title ;
}
function fof_get_items ( $user_id , $feed = NULL , $what = " unread " , $when = NULL , $start = NULL , $limit = NULL , $order = " desc " , $search = NULL )
{
2009-10-26 16:16:15 +03:00
global $fof_item_filters ;
$items = fof_db_get_items ( $user_id , $feed , $what , $when , $start , $limit , $order , $search );
2010-01-25 20:30:38 +03:00
for ( $i = 0 ; $i < count ( $items ); $i ++ )
2009-10-26 16:16:15 +03:00
{
foreach ( $fof_item_filters as $filter )
$items [ $i ][ 'item_content' ] = $filter ( $items [ $i ][ 'item_content' ]);
2010-01-25 20:30:38 +03:00
$items [ $i ][ 'feed_title' ] = fof_feed_title ( $items [ $i ]);
2009-10-26 16:16:15 +03:00
}
return $items ;
2009-08-03 16:42:04 +04:00
}
function fof_get_item ( $user_id , $item_id )
2009-10-26 16:16:15 +03:00
{
global $fof_item_filters ;
$item = fof_db_get_item ( $user_id , $item_id );
foreach ( $fof_item_filters as $filter )
$item [ 'item_content' ] = $filter ( $item [ 'item_content' ]);
2010-01-25 20:30:38 +03:00
$item [ 'feed_title' ] = fof_feed_title ( $item );
2009-10-26 16:16:15 +03:00
return $item ;
2009-08-03 16:42:04 +04:00
}
function fof_mark_read ( $user_id , $items )
{
fof_db_mark_read ( $user_id , $items );
}
function fof_mark_unread ( $user_id , $items )
{
fof_db_mark_unread ( $user_id , $items );
}
function fof_delete_subscription ( $user_id , $feed_id )
{
fof_db_delete_subscription ( $user_id , $feed_id );
2009-10-26 16:16:15 +03:00
2014-11-24 02:40:04 +03:00
if ( mysql_num_rows ( fof_db_get_subscribed_users ( $feed_id )) == 0 )
2009-08-03 16:42:04 +04:00
{
2009-10-26 16:16:15 +03:00
fof_db_delete_feed ( $feed_id );
2009-08-03 16:42:04 +04:00
}
}
function fof_get_nav_links ( $feed = NULL , $what = " new " , $when = NULL , $start = NULL , $limit = NULL )
{
$prefs = fof_prefs ();
$string = " " ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( ! is_null ( $when ) && $when != " " )
{
if ( $when == " today " )
2010-01-25 20:30:38 +03:00
$whendate = fof_todays_date ();
2009-08-03 16:42:04 +04:00
else
2010-01-25 20:30:38 +03:00
$whendate = $when ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$begin = strtotime ( $whendate );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$tomorrow = date ( " Y/m/d " , $begin + ( 24 * 60 * 60 ) );
$yesterday = date ( " Y/m/d " , $begin - ( 24 * 60 * 60 ) );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$string .= " <a href= \" .?feed= $feed &what= $what &when= $yesterday &how= $how &howmany= $howmany\ " > [ & laquo ; $yesterday ] </ a > " ;
if ( $when != " today " ) $string .= " <a href= \" .?feed= $feed &what= $what &when=today&how= $how &howmany= $howmany\ " > [ today ] </ a > " ;
if ( $when != " today " ) $string .= " <a href= \" .?feed= $feed &what= $what &when= $tomorrow &how= $how &howmany= $howmany\ " > [ $tomorrow & raquo ;] </ a > " ;
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( is_numeric ( $start ))
{
if ( ! is_numeric ( $limit )) $limit = $prefs [ " howmany " ];
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$earlier = $start + $limit ;
$later = $start - $limit ;
2009-10-26 16:16:15 +03:00
2011-09-09 21:47:54 +04:00
$string .= " <a href= \" .?feed= $feed &what= $what &when= $when &which= $earlier &howmany= $limit\ " > [ & laquo ; previous $limit ] </ a > " ;
if ( $later >= 0 ) $string .= " <a href= \" .?feed= $feed &what= $what &when= $when &howmany= $limit\ " > [ current items ] </ a > " ;
if ( $later >= 0 ) $string .= " <a href= \" .?feed= $feed &what= $what &when= $when &which= $later &howmany= $limit\ " > [ next $limit & raquo ;] </ a > " ;
2009-08-03 16:42:04 +04:00
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
return $string ;
}
function fof_render_feed_link ( $row )
{
2009-10-26 16:16:15 +03:00
$link = $row [ 'feed_link' ];
$description = $row [ 'feed_description' ];
2010-01-25 20:30:38 +03:00
$title = htmlspecialchars ( fof_feed_title ( $row ), ENT_QUOTES );
2009-10-26 16:16:15 +03:00
$url = $row [ 'feed_url' ];
2009-08-03 16:42:04 +04:00
2009-10-26 16:16:15 +03:00
$s = " <b><a href= \" $link\ " title = \ " $description\ " > $title </ a ></ b > " ;
2011-10-17 23:13:00 +04:00
$s .= " <a href= \" $url\ " > ( feed ) </ a > " ;
2009-08-03 16:42:04 +04:00
2009-10-26 16:16:15 +03:00
return $s ;
2009-08-03 16:42:04 +04:00
}
function fof_opml_to_array ( $opml )
{
2009-10-26 16:16:15 +03:00
$rx = " /xmlurl= \" (.*?) \" /mi " ;
if ( preg_match_all ( $rx , $opml , $m ))
{
for ( $i = 0 ; $i < count ( $m [ 0 ]) ; $i ++ )
{
$r [] = $m [ 1 ][ $i ];
}
2009-08-03 16:42:04 +04:00
}
return $r ;
}
function fof_prepare_url ( $url )
{
2009-10-26 16:16:15 +03:00
$url = trim ( $url );
2009-08-03 16:42:04 +04:00
2009-10-26 16:16:15 +03:00
if ( substr ( $url , 0 , 7 ) == " feed:// " ) $url = substr ( $url , 7 );
2009-08-03 16:42:04 +04:00
2009-10-26 16:16:15 +03:00
if ( substr ( $url , 0 , 7 ) != 'http://' && substr ( $url , 0 , 8 ) != 'https://' )
2009-12-07 01:12:15 +03:00
$url = 'http://' . $url ;
2009-08-03 16:42:04 +04:00
return $url ;
}
2012-02-21 15:11:35 +04:00
function fof_subscribe ( $user_id , $url , $unread = " today " )
2009-08-03 16:42:04 +04:00
{
2012-02-21 15:11:35 +04:00
if ( ! $url )
return array ( " Empty URL " , false );
2009-10-26 16:16:15 +03:00
$url = fof_prepare_url ( $url );
2009-08-03 16:42:04 +04:00
$feed = fof_db_get_feed_by_url ( $url );
2009-10-26 16:16:15 +03:00
2012-02-21 15:11:35 +04:00
if ( fof_is_subscribed ( $user_id , $url ))
return array ( " You are already subscribed to " . fof_render_feed_link ( $feed ), $feed );
2009-10-26 16:16:15 +03:00
2012-02-21 15:11:35 +04:00
if ( fof_feed_exists ( $url ))
2009-08-03 16:42:04 +04:00
{
fof_db_add_subscription ( $user_id , $feed [ 'feed_id' ]);
fof_apply_plugin_tags ( $id , NULL , $user_id );
fof_update_feed ( $feed [ 'feed_id' ]);
2009-10-26 16:16:15 +03:00
2012-02-21 15:11:35 +04:00
if ( $unread != " no " )
fof_db_mark_feed_unread ( $user_id , $feed [ 'feed_id' ], $unread );
return array ( '<font color="green"><b>Subscribed.</b></font>' , $feed );
2009-08-03 16:42:04 +04:00
}
2009-10-26 16:16:15 +03:00
2011-07-21 15:25:55 +04:00
$rss = fof_parse ( $url , $user_id );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( isset ( $rss -> error ))
2012-02-21 15:11:35 +04:00
return array ( " Error: <b> " . $rss -> error . " </b> " , $feed );
2009-08-03 16:42:04 +04:00
else
{
2012-02-21 23:14:39 +04:00
// Changing saved feed URL automatically is a fucking bad idea!
// It's very unpleasant to see that URL just changed sometime
// by itself because the remote site had an error and gave FOF
// some crap instead of real feed.
// The another problem is handling feeds with authorization data
// in the feed link: such feeds don't usually include login and
// password inside the 'self' link.
// So we don't change URLs in any way (original FOF did).
2009-10-26 16:16:15 +03:00
2012-02-21 15:11:35 +04:00
$id = fof_add_feed ( $url , rss_feed_title ( $rss ), $rss -> get_link (), $rss -> get_description ());
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
fof_update_feed ( $id );
fof_db_add_subscription ( $user_id , $id );
2012-02-21 15:11:35 +04:00
if ( $unread != " no " )
fof_db_mark_feed_unread ( $user_id , $id , $unread );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
fof_apply_plugin_tags ( $id , NULL , $user_id );
2009-10-26 16:16:15 +03:00
2012-02-21 15:11:35 +04:00
$feed = fof_db_get_feed_by_id ( $id );
return array ( '<font color="green"><b>Subscribed.</b></font>' , $feed );
2009-08-03 16:42:04 +04:00
}
}
function fof_add_feed ( $url , $title , $link , $description )
{
2012-02-21 15:11:35 +04:00
if ( $title == " " )
$title = " [no title] " ;
2009-08-03 16:42:04 +04:00
2012-02-21 15:11:35 +04:00
return fof_db_add_feed ( $url , $title , $link , $description );
2009-08-03 16:42:04 +04:00
}
function fof_is_subscribed ( $user_id , $url )
{
2012-02-21 15:11:35 +04:00
return fof_db_is_subscribed ( $user_id , $url );
2009-08-03 16:42:04 +04:00
}
function fof_feed_exists ( $url )
{
2009-10-26 16:16:15 +03:00
$feed = fof_db_get_feed_by_url ( $url );
2009-08-03 16:42:04 +04:00
2009-10-26 16:16:15 +03:00
return $feed ;
2009-08-03 16:42:04 +04:00
}
2011-07-21 15:25:55 +04:00
function fof_generate_sudo_id ()
2009-08-03 16:42:04 +04:00
{
2011-07-21 15:25:55 +04:00
global $fof_sudo_id_user ;
$sudo_id = unpack ( 'H*' , urandom ( 16 ));
$sudo_id = $sudo_id [ 1 ];
fof_cache_set ( " sudo- $sudo_id " , $fof_sudo_id_user , 30 );
return " fof_sudo_id= $sudo_id " ;
}
function fof_parse ( $url , $as_user = NULL )
{
$p = FoF_Prefs :: instance ();
2009-08-03 16:42:04 +04:00
$admin_prefs = $p -> admin_prefs ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$pie = new SimplePie ();
2011-07-21 15:25:55 +04:00
/* Bug 63447 - Allow FoF to securely pass user authorization without verification */
if ( ! is_null ( $as_user ) && strpos ( $url , " fof_sudo " ) !== false )
{
global $fof_sudo_id_user ;
$fof_sudo_id_user = $as_user ;
$pie -> headers [ 'Cookie' ] = new SimplePie_Callback ( 'fof_generate_sudo_id' );
}
2009-08-03 16:42:04 +04:00
$pie -> set_cache_duration ( $admin_prefs [ " manualtimeout " ] * 60 );
$pie -> set_favicon_handler ( " favicon.php " );
2009-10-26 16:16:15 +03:00
$pie -> set_feed_url ( $url );
$pie -> set_javascript ( false );
$pie -> remove_div ( false );
$pie -> init ();
return $pie ;
2009-08-03 16:42:04 +04:00
}
2009-12-07 01:12:15 +03:00
function fof_apply_tags ( $item )
2009-08-03 16:42:04 +04:00
{
global $fof_subscription_to_tags ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( ! isset ( $fof_subscription_to_tags ))
$fof_subscription_to_tags = fof_db_get_subscription_to_tags ();
2009-10-26 16:16:15 +03:00
2009-12-07 01:12:15 +03:00
// add subscription tags
foreach (( array ) $fof_subscription_to_tags [ $item [ 'feed_id' ]] as $user_id => $tags )
2009-08-03 16:42:04 +04:00
if ( is_array ( $tags ))
2009-12-07 01:12:15 +03:00
foreach ( $tags as $tag )
fof_db_tag_items ( $user_id , $tag , $item [ 'item_id' ]);
2009-10-26 16:16:15 +03:00
$filtered = array ();
2009-12-07 01:12:15 +03:00
// filter duplicate items
$dup = fof_db_get_is_duplicate_item ( $item [ 'item_id' ], $item [ 'item_guid' ], md5 ( $item [ 'item_content' ]));
foreach ( $dup as $user_id )
$filtered [ $user_id ] = true ;
// regexp filter items
foreach (( array ) $fof_subscription_to_tags [ 'filter' ][ $item [ 'feed_id' ]] as $user_id => $filter )
2009-10-26 16:16:15 +03:00
if ( $filter && ( preg_match ( $filter , $title ) || preg_match ( $filter , $content )))
2009-12-07 01:12:15 +03:00
$filtered [ $user_id ] = true ;
2009-10-26 16:16:15 +03:00
2009-12-07 01:12:15 +03:00
// mark item as unread for some users
2014-11-24 02:34:08 +03:00
fof_db_mark_item_unread ( $item [ 'item_id' ], array_keys ( $filtered ));
2009-08-03 16:42:04 +04:00
}
2010-01-25 20:30:38 +03:00
function rss_feed_title ( $rss )
{
return html_entity_decode ( strip_tags ( $rss -> get_title ()), ENT_QUOTES );
}
2011-07-21 15:25:55 +04:00
function fof_update_feed ( $id , $as_user = NULL )
2009-08-03 16:42:04 +04:00
{
2012-02-22 10:46:32 +04:00
if ( ! $id )
return 0 ;
2009-10-26 16:16:15 +03:00
2011-07-21 15:25:55 +04:00
if ( $as_user === NULL )
$as_user = fof_db_get_feed_single_user ( $id );
2009-08-03 16:42:04 +04:00
$feed = fof_db_get_feed_by_id ( $id );
$url = $feed [ 'feed_url' ];
fof_log ( " Updating $url " );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
fof_db_feed_mark_attempted_cache ( $id );
2009-10-26 16:16:15 +03:00
2011-07-21 15:25:55 +04:00
$rss = fof_parse ( $feed [ 'feed_url' ], $as_user );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( $rss -> error ())
{
fof_log ( " feed update failed: " . $rss -> error (), " update " );
2011-07-21 15:25:55 +04:00
return array ( 0 , " Error: <b> " . $rss -> error () . " </b> " );
2009-08-03 16:42:04 +04:00
}
2009-10-26 16:16:15 +03:00
2012-02-22 10:46:32 +04:00
// Changing saved feed URL automatically is a fucking bad idea!
// It's very unpleasant to see that URL just changed sometime
// by itself because the remote site had an error and gave FOF
// some crap instead of real feed.
// The another problem is handling feeds with authorization data
// in the feed link: such feeds don't usually include login and
// password inside the 'self' link.
// So we don't change URLs in any way (original FOF did).
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$image = $feed [ 'feed_image' ];
$image_cache_date = $feed [ 'feed_image_cache_date' ];
2009-10-26 16:16:15 +03:00
2012-02-22 10:46:32 +04:00
if ( $feed [ 'feed_image_cache_date' ] < ( time () - ( 7 * 24 * 60 * 60 )))
2009-08-03 16:42:04 +04:00
{
$image = $rss -> get_favicon ();
$image_cache_date = time ();
}
2009-10-26 16:16:15 +03:00
2010-01-25 20:30:38 +03:00
$title = rss_feed_title ( $rss );
2012-02-22 10:46:32 +04:00
if ( $title == " " )
$title = " [no title] " ;
2009-10-26 16:16:15 +03:00
2012-02-22 10:46:32 +04:00
fof_db_feed_update_metadata ( $id , $feed [ 'feed_url' ], $title ,
$rss -> get_link (), $rss -> get_description (), $image , $image_cache_date );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$feed_id = $feed [ 'feed_id' ];
$n = 0 ;
2009-10-26 16:16:15 +03:00
if ( $feed [ 'feed_filter' ])
{
$filter = @ unserialize ( $feed [ 'feed_filter' ]);
if ( ! $filter || ! $filter [ 're' ] || ! $filter [ 'tags' ])
2009-12-07 01:12:15 +03:00
$filter = NULL ;
2009-10-26 16:16:15 +03:00
else
2009-12-07 01:12:15 +03:00
$filter [ 'tags' ] = preg_split ( '/[\s,]*,[\s,]*/' , $filter [ 'tags' ]);
2009-10-26 16:16:15 +03:00
}
2009-08-03 16:42:04 +04:00
if ( $rss -> get_items ())
{
foreach ( $rss -> get_items () as $item )
{
2009-12-07 01:12:15 +03:00
$link = $item -> get_permalink ();
2010-02-15 22:06:58 +03:00
$author = $item -> get_authors ();
2010-02-15 22:51:51 +03:00
if ( $author )
2010-02-15 22:06:58 +03:00
{
2010-02-15 22:51:51 +03:00
foreach ( $author as & $a )
{
$an = htmlspecialchars ( $a -> get_name ());
$al = htmlspecialchars ( $a -> get_link ());
$ae = htmlspecialchars ( $a -> get_email ());
if ( $al )
$a = " <a href= \" $al\ " > $an </ a > " ;
else if ( $ae )
$a = " <a href= \" mailto: $ae\ " > $an </ a > " ;
else
$a = $an ;
}
$author = implode ( ', ' , $author );
2010-02-15 22:06:58 +03:00
}
2010-02-15 22:51:51 +03:00
else
$author = '' ;
2009-12-07 01:12:15 +03:00
$title = $item -> get_title ();
$content = $item -> get_content ();
$date = $item -> get_date ( 'U' );
if ( ! $date ) $date = time ();
$item_id = $item -> get_id ();
if ( ! $item_id )
$item_id = $link ;
$id = fof_db_find_item ( $feed_id , $item_id );
2009-10-26 16:16:15 +03:00
2009-12-07 01:12:15 +03:00
if ( $id == NULL )
{
$n ++ ;
2009-10-26 16:16:15 +03:00
2009-12-07 01:12:15 +03:00
global $fof_item_prefilters ;
2012-03-03 00:31:25 +04:00
foreach ( $fof_item_prefilters as $filter )
2009-12-07 01:12:15 +03:00
list ( $link , $title , $content ) = $filter ( $item , $link , $title , $content );
2009-08-03 16:42:04 +04:00
2010-02-15 22:06:58 +03:00
$id = fof_db_add_item ( $feed_id , array (
'item_guid' => $item_id ,
'item_link' => $link ,
'item_title' => $title ,
'item_author' => $author ,
'item_content' => $content ,
'item_cached' => time (),
'item_published' => $date ,
'item_updated' => $date ,
));
2009-12-07 01:12:15 +03:00
$fof_item = fof_db_get_item_by_id ( $id );
fof_apply_tags ( $fof_item );
fof_apply_plugin_tags ( $feed_id , $id , NULL );
}
$ids [] = $id ;
2009-08-03 16:42:04 +04:00
}
}
// optionally purge old items - if 'purge' is set we delete items that are not
// unread or starred, not currently in the feed or within sizeof(feed) items
// of being in the feed, and are over 'purge' many days old
2009-10-26 16:16:15 +03:00
2012-12-31 14:24:42 +04:00
$p = FoF_Prefs :: instance ();
2009-08-03 16:42:04 +04:00
$admin_prefs = $p -> admin_prefs ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
if ( $admin_prefs [ 'purge' ] != " " )
{
fof_log ( 'purge is ' . $admin_prefs [ 'purge' ]);
$count = count ( $ids );
fof_log ( 'items in feed: ' . $count );
if ( count ( $ids ) != 0 )
{
2009-12-07 01:12:15 +03:00
$in = implode ( " , " , $ids );
2009-10-26 16:16:15 +03:00
2009-12-07 01:12:15 +03:00
global $FOF_ITEM_TABLE , $FOF_ITEM_TAG_TABLE ;
$sql = " select item_id, item_cached from $FOF_ITEM_TABLE where feed_id = $feed_id and item_id not in ( $in ) order by item_cached desc limit $count , 1000000000 " ;
$result = fof_db_query ( $sql );
2009-10-26 16:16:15 +03:00
2009-12-07 01:12:15 +03:00
while ( $row = fof_db_get_row ( $result ))
if ( $row [ 'item_cached' ] < ( time () - ( $admin_prefs [ 'purge' ] * 24 * 60 * 60 )))
if ( ! fof_item_has_tags ( $row [ 'item_id' ]))
$delete [] = $row [ 'item_id' ];
2009-10-26 16:16:15 +03:00
2009-12-07 01:12:15 +03:00
$ndelete = count ( $delete );
if ( count ( $delete ) != 0 )
{
$in = implode ( " , " , $delete );
fof_db_query ( " delete from $FOF_ITEM_TABLE where item_id in ( $in ) " );
fof_db_query ( " delete from $FOF_ITEM_TAG_TABLE where item_id in ( $in ) " );
}
2009-08-03 16:42:04 +04:00
}
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
unset ( $rss );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
fof_db_feed_mark_cached ( $feed_id );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$log = " feed update complete, $n new items, $ndelete items purged " ;
if ( $admin_prefs [ 'purge' ] == " " )
{
$log .= " (purging disabled) " ;
}
fof_log ( $log , " update " );
return array ( $n , " " );
}
function fof_apply_plugin_tags ( $feed_id , $item_id = NULL , $user_id = NULL )
{
$users = array ();
if ( $user_id )
$users [] = $user_id ;
else
{
2014-11-24 02:40:04 +03:00
$result = fof_db_get_subscribed_users ( $feed_id );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
while ( $row = fof_db_get_row ( $result ))
2009-12-07 01:12:15 +03:00
$users [] = $row [ 'user_id' ];
2009-08-03 16:42:04 +04:00
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$items = array ();
if ( $item_id )
$items [] = fof_db_get_item ( $user_id , $item_id );
else
{
$result = fof_db_get_items ( $user_id , $feed_id , $what = " all " , NULL , NULL );
foreach ( $result as $r )
2009-12-07 01:12:15 +03:00
$items [] = $r ;
2009-08-03 16:42:04 +04:00
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$userdata = fof_get_users ();
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
foreach ( $users as $user )
{
fof_log ( " tagging for $user " );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
global $fof_tag_prefilters ;
foreach ( $fof_tag_prefilters as $plugin => $filter )
{
2009-12-07 01:12:15 +03:00
fof_log ( " considering $plugin $filter " );
2009-10-26 16:16:15 +03:00
2009-12-07 01:12:15 +03:00
if ( ! $userdata [ $user ][ 'prefs' ][ 'plugin_' . $plugin ])
{
foreach ( $items as $item )
2009-08-03 16:42:04 +04:00
{
2009-12-07 01:12:15 +03:00
$tags = $filter ( $item [ 'item_link' ], $item [ 'item_title' ], $item [ 'item_content' ]);
fof_tag_item ( $user , $item [ 'item_id' ], $tags );
2009-08-03 16:42:04 +04:00
}
2009-12-07 01:12:15 +03:00
}
2009-08-03 16:42:04 +04:00
}
}
}
function fof_item_has_tags ( $item_id )
{
2009-10-26 16:16:15 +03:00
return fof_db_item_has_tags ( $item_id );
2009-08-03 16:42:04 +04:00
}
function fof_init_plugins ()
{
2009-10-26 16:16:15 +03:00
global $fof_item_filters , $fof_item_prefilters , $fof_tag_prefilters , $fof_plugin_prefs ;
2009-08-03 16:42:04 +04:00
$fof_item_filters = array ();
$fof_item_prefilters = array ();
$fof_plugin_prefs = array ();
2009-10-26 16:16:15 +03:00
$fof_tag_prefilters = array ();
2009-08-03 16:42:04 +04:00
2012-03-03 00:31:25 +04:00
$p = FoF_Prefs :: instance ();
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$dirlist = opendir ( FOF_DIR . " /plugins " );
2009-11-09 14:30:36 +03:00
while ( $file = readdir ( $dirlist ))
2009-08-03 16:42:04 +04:00
{
2009-10-26 16:16:15 +03:00
fof_log ( " considering " . $file );
2009-11-09 14:30:36 +03:00
if ( ereg ( '\.php$' , $file ) &&
is_readable ( FOF_DIR . " /plugins/ " . $file ) &&
! $p -> get ( 'plugin_' . substr ( $file , 0 , - 4 )))
2009-08-03 16:42:04 +04:00
{
2009-11-09 14:30:36 +03:00
fof_log ( " including " . $file );
include ( FOF_DIR . " /plugins/ " . $file );
2009-08-03 16:42:04 +04:00
}
}
closedir ();
}
function fof_add_tag_prefilter ( $plugin , $function )
{
global $fof_tag_prefilters ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$fof_tag_prefilters [ $plugin ] = $function ;
}
function fof_add_item_filter ( $function )
{
global $fof_item_filters ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$fof_item_filters [] = $function ;
}
function fof_add_item_prefilter ( $function )
{
global $fof_item_prefilters ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$fof_item_prefilters [] = $function ;
}
function fof_add_pref ( $name , $key , $type = " string " )
{
global $fof_plugin_prefs ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$fof_plugin_prefs [] = array ( $name , $key , $type );
}
function fof_add_item_widget ( $function )
{
global $fof_item_widgets ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
$fof_item_widgets [] = $function ;
}
function fof_get_widgets ( $item )
{
global $fof_item_widgets ;
if ( ! is_array ( $fof_item_widgets ))
{
2009-10-26 16:16:15 +03:00
return false ;
}
2009-08-03 16:42:04 +04:00
2014-12-09 16:07:00 +03:00
$widgets = array ();
foreach ( $fof_item_widgets as $widget )
2009-08-03 16:42:04 +04:00
{
$w = $widget ( $item );
2014-12-09 16:07:00 +03:00
if ( $w )
$widgets [] = $w ;
2009-08-03 16:42:04 +04:00
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
return $widgets ;
}
function fof_get_plugin_prefs ()
{
global $fof_plugin_prefs ;
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
return $fof_plugin_prefs ;
}
function fof_multi_sort ( $tab , $key , $rev )
{
if ( $rev )
{
$compare = create_function ( '$a,$b' , 'if (strtolower($a["' . $key . '"]) == strtolower($b["' . $key . '"])) {return 0;}else {return (strtolower($a["' . $key . '"]) > strtolower($b["' . $key . '"])) ? -1 : 1;}' );
}
else
{
$compare = create_function ( '$a,$b' , 'if (strtolower($a["' . $key . '"]) == strtolower($b["' . $key . '"])) {return 0;}else {return (strtolower($a["' . $key . '"]) < strtolower($b["' . $key . '"])) ? -1 : 1;}' );
}
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
usort ( $tab , $compare ) ;
return $tab ;
}
function fof_todays_date ()
{
$prefs = fof_prefs ();
$offset = $prefs [ 'tzoffset' ];
2011-07-21 15:25:55 +04:00
if ( $prefs [ 'dst' ])
$offset += date ( 'I' );
2009-10-26 16:16:15 +03:00
2009-08-03 16:42:04 +04:00
return gmdate ( " Y/m/d " , time () + ( $offset * 60 * 60 ) );
}
function fof_repair_drain_bamage ()
{
2009-10-26 16:16:15 +03:00
if ( ini_get ( 'register_globals' ))
foreach ( $_REQUEST as $k => $v )
unset ( $GLOBALS [ $k ]);
2009-08-03 16:42:04 +04:00
// thanks to submitter of http://bugs.php.net/bug.php?id=39859
2009-10-26 16:16:15 +03:00
if ( get_magic_quotes_gpc ())
{
function undoMagicQuotes ( $array , $topLevel = true )
{
2009-08-03 16:42:04 +04:00
$newArray = array ();
2009-10-26 16:16:15 +03:00
foreach ( $array as $key => $value )
{
if ( ! $topLevel )
2009-08-03 16:42:04 +04:00
$key = stripslashes ( $key );
2009-10-26 16:16:15 +03:00
if ( is_array ( $value ))
2009-08-03 16:42:04 +04:00
$newArray [ $key ] = undoMagicQuotes ( $value , false );
2009-10-26 16:16:15 +03:00
else
2009-08-03 16:42:04 +04:00
$newArray [ $key ] = stripslashes ( $value );
}
return $newArray ;
}
$_GET = undoMagicQuotes ( $_GET );
$_POST = undoMagicQuotes ( $_POST );
$_COOKIE = undoMagicQuotes ( $_COOKIE );
$_REQUEST = undoMagicQuotes ( $_REQUEST );
}
}
// for PHP 4 compatibility
if ( ! function_exists ( 'str_ireplace' ))
{
function str_ireplace ( $search , $replace , $subject )
{
$search = preg_quote ( $search , " / " );
return preg_replace ( " / " . $search . " /i " , $replace , $subject );
}
}