Пример #1
0
 public function getUrl()
 {
     Phpfox_Error::skip(true);
     $mReturn = $this->_oTwitter->getAuthorizationUrl();
     Phpfox_Error::skip(false);
     return $mReturn;
 }
Пример #2
0
 /**
  * Uses the class DOMDocument to clean HTML and make it valid XHTML.
  *
  * @link http://php.net/manual/en/class.domdocument.php 
  * @param string $sStr String we need to parse.
  * @return string Parsed string withn clean valid XHTML code.
  */
 public function validXhtml($sStr)
 {
     if (class_exists('DOMDocument')) {
         static $oDoc = null;
         if ($oDoc === null) {
             $oDoc = new DOMDocument('1.0');
         }
         Phpfox_Error::skip(true);
         $oDoc->loadHTML($sStr);
         $sStr = $oDoc->saveHTML();
         $sStr = preg_replace('/^<!DOCTYPE.+?>/i', '', $sStr);
         $sStr = trim($sStr);
         if (substr($sStr, 0, 12) == '<html><body>') {
             $sStr = substr_replace($sStr, '', 0, 12);
         }
         if (substr($sStr, -14) == '</body></html>') {
             $sStr = substr_replace($sStr, '', -14);
         }
         Phpfox_Error::skip(false);
     }
     return $sStr;
 }
Пример #3
0
	public function update($aVals)
	{		
		if (isset($aVals['order']))
		{
			foreach ($aVals['order'] as $sVar => $iOrder)
			{
				$this->database()->update($this->_sTable, array('ordering' => (int) $iOrder), "var_name = '" . $this->database()->escape($sVar) . "'");
			}		
		}
				
		if (isset($aVals['value']['admin_debug_mode']) && file_exists(PHPFOX_DIR . 'file' . PHPFOX_DS . 'cache' . PHPFOX_DS . 'debug.php'))
		{
			Phpfox::getLib('file')->unlink(PHPFOX_DIR . 'file' . PHPFOX_DS . 'cache' . PHPFOX_DS . 'debug.php');
		}
		
		if (isset($aVals['value']['ftp_enabled']) && $aVals['value']['ftp_enabled'])
		{			
			define('PHPFOX_FTP_LOGIN_PASS', true);
	
			if (Phpfox::getLib('ftp')->connect($aVals['value']['ftp_host'], $aVals['value']['ftp_username'], $aVals['value']['ftp_password']))
			{
				if (!Phpfox::getLib('ftp')->test($aVals['value']['ftp_dir_path']))
				{
					return false;
				}
			}
			
			if (!Phpfox_Error::isPassed())
			{
				return false;
			}			
		}
		
		if (isset($aVals['value']['enable_api_support']) && $aVals['value']['enable_api_support'])
		{
			if (!Phpfox::getService('api')->test())
			{
				return false;
			}
		}
		
		if (isset($aVals['value']['enable_janrain_login']) && $aVals['value']['enable_janrain_login'] == 1 &&
			( (isset($aVals['value']['janrain_api_key']) && empty($aVals['value']['janrain_api_key'])) ||
				(isset($aVals['value']['janrain_application_domain']) && empty($aVals['value']['janrain_application_domain']))
			)
			)
		{			
			return Phpfox_Error::set('To enable Janrain you must set the API Key and the Application domain');
		}
		
		if (isset($aVals['value']['method']) && $aVals['value']['method']['value'] == 'smtp')
		{			
			Phpfox_Error::skip(true);
			
			$bSent = Phpfox::getLib('mail', 'smtp')->test($aVals['value'])
				->to($aVals['value']['email_from_email'])
				->subject('Test SMTP E-mail')
				->message('SMTP is working!')
				->send();				
				
			if ($bSent === false)
			{
				$sEmailHeader = ob_get_contents();
				
				ob_clean();
				
				if (!empty($sEmailHeader))
				{
					Phpfox_Error::set('<b>SMTP Error Message</b>: ' . $sEmailHeader);
				}
				
				return false;
			}
			
			Phpfox_Error::skip(false);
		}			

		if (!empty($_FILES['watermark']['name']))
		{
			$aImage = Phpfox::getLib('file')->load('watermark', array('jpg', 'gif', 'png'));
			if ($aImage === false)
			{
				return false;
			}
			
			$hDir = opendir(Phpfox::getParam('core.dir_watermark'));
			while ($sFile = readdir($hDir))
			{
				if (!preg_match('/(.*)\.(jpg|jpeg|gif|png)/i', $sFile))
				{
					continue;
				}
				
				Phpfox::getLib('file')->unlink(Phpfox::getParam('core.dir_watermark') . $sFile);
			}
			closedir($hDir);
			
			if (!Phpfox::getLib('file')->upload('watermark', Phpfox::getParam('core.dir_watermark'), 'watermark', false, 0644, false))
			{
				return false;	
			}
			
			$aVals['value']['watermark_image'] = 'watermark%s.' . $aImage['ext'];			
		}		
		
		$aValues = array();

		if (!isset($aVals['value']))
		{ // when logged out because of inactivity and refresh and resubmit it would throw an undefined index error
				$this->cache()->remove();
				return true;
		}
		foreach ($aVals['value'] as $sKey => $mValue)
		{
			if (is_array($mValue))
			{
				if ($sKey == 'captcha_font')
				{
					$aValues['value_actual'] = $mValue['value'];	
				}
				else 
				{
					if (isset($mValue['real']) && isset($mValue['value']))
					{
						$mValue['value'] = trim($mValue['value']);
						$aSub = array();
						$aSub[] = $mValue['value'];
						$aParts = explode(',', $mValue['real']);					
						foreach ($aParts as $sPart)
						{
							$sPart = trim($sPart);
							if ($sPart == $mValue['value'])
							{
								continue;
							}
							$aSub[] = $sPart;
						}
						
						if ($sKey == 'admin_debug_mode' && $mValue['value'] != 'Level 0')
						{
							Phpfox::getLib('file')->writeToCache('debug.php', '<?php define(\'PHPFOX_DEBUG\', true); define(\'PHPFOX_DEBUG_LEVEL\', ' . trim(str_replace('Level', '', $mValue['value'])) . '); ?>');
						}
						
						// Prepare the array for the database
						$aValues['value_actual'] = serialize(array(
								'default' => $mValue['value'],
								'values' => $aSub
							)
						);
					}
					else 
					{
						$aCached = array();
						foreach ($mValue as $iValueKey => $sValueKey)
						{						
							// Make sure we don't have any duplicate values
							if (isset($aCached[$sValueKey]))
							{
								// Remove the duplicate value
								unset($mValue[$iValueKey]);
							}
							// Cache for duplicate value check
							$aCached[$sValueKey] = $sValueKey;
						}
			
						// Prepare the array for the database
						$aValues['value_actual'] = serialize(str_replace('array ', 'array', var_export($mValue, true)) . ';');
					}
				}
			}
			else 
			{
				if ($sKey == 'title_delim' || $sKey == 'required_symbol')
				{
					$mValue = Phpfox::getLib('parse.input')->convert($mValue);
				}
				
				// Encode the ftp password with the server salt
				if ($sKey == 'ftp_password')
				{
					$mValue = base64_encode(base64_encode($mValue . md5(Phpfox::getParam('core.salt'))));
				}			
				
				if ($sKey == 'session_prefix')
				{
					$mValue = substr(preg_replace("/[^A-Za-z0-9]/", "", $mValue), 0, 15);					
				}
				
				// clear the cache from the featured users
				if ($sKey == 'how_many_featured_members')
				{
					$this->cache()->remove('featured_users');
				}
				$aValues['value_actual'] = $mValue;
				
				if ($sKey == 'admin_cp' && $mValue != 'admincp')
				{
					if (!Phpfox::getLib('parse.input')->allowTitle($mValue, Phpfox::getPhrase('admincp.admincp_name_not_allowed') . ': ' . strip_tags($mValue)))
					{
						return false;
					}					
				}
				
				if ($sKey == 'allow_video_uploading' && $mValue == '1')
				{
					$aVals['value']['ffmpeg_path'] = Phpfox::getParam('video.ffmpeg_path');
					$aVals['value']['mencoder_path'] = Phpfox::getParam('video.mencoder_path');
					
					if (!($mReturn = Phpfox::getService('video')->requirementCheck($aVals['value'])))
					{
						return false;
					}
				}
				
				if ($sKey == 'profile_use_id' && $mValue == '1')
				{
					$aUsers = $this->database()->select('user_id')	
						->from(Phpfox::getT('user'))
						->execute('getRows');
					foreach ($aUsers as $aUser)
					{
						$this->database()->update(Phpfox::getT('user'), array('user_name' => 'profile-' . $aUser['user_id']), 'user_id = ' . $aUser['user_id']);
					}
				}
			}						
	
			$this->database()->update($this->_sTable, $aValues, "var_name = '" . $this->database()->escape($sKey) . "'");
		}		

		// Clear the setting cache
		$this->cache()->remove();
		
		// Phpfox::getLib('setting')->set();
		
		return true;
	}
Пример #4
0
 public function upload($aVals, $iAlbumId = 0)
 {
     if (!isset($_FILES['mp3'])) {
         return Phpfox_Error::set(Phpfox::getPhrase('music.select_an_mp3'));
     }
     $aSong = Phpfox::getLib('file')->load('mp3', 'mp3', Phpfox::getUserParam('music.music_max_file_size'));
     if (function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         if (!in_array(finfo_file($finfo, $_FILES['mp3']['tmp_name']), Phpfox::getService('music')->getMimeTypes())) {
             return Phpfox_Error::set(Phpfox::getPhrase('core.uploaded_file_is_not_valid'));
         }
         finfo_close($finfo);
     }
     if ($aSong === false) {
         return false;
     }
     if (empty($aVals['title'])) {
         $aVals['title'] = $aSong['name'];
     }
     if (!isset($aVals['privacy'])) {
         $aVals['privacy'] = 0;
     }
     if (!isset($aVals['privacy_comment'])) {
         $aVals['privacy_comment'] = 0;
     }
     if ($iAlbumId < 1 && isset($aVals['album_id'])) {
         $iAlbumId = (int) $aVals['album_id'];
     }
     if ($iAlbumId > 0) {
         $aAlbum = $this->database()->select('*')->from(Phpfox::getT('music_album'))->where('album_id = ' . (int) $iAlbumId)->execute('getSlaveRow');
         $aVals['privacy'] = $aAlbum['privacy'];
         $aVals['privacy_comment'] = $aAlbum['privacy_comment'];
         if (!empty($aAlbum['module_id'])) {
             $aVals['callback_module'] = $aAlbum['module_id'];
         }
         if (!empty($aAlbum['item_id'])) {
             $aVals['callback_item_id'] = $aAlbum['item_id'];
         }
     }
     if (!empty($aVals['new_album_title'])) {
         $iAlbumId = $this->database()->insert(Phpfox::getT('music_album'), array('user_id' => Phpfox::getUserId(), 'name' => $this->preParse()->clean($aVals['new_album_title']), 'privacy' => isset($aVals['privacy']) ? $aVals['privacy'] : '0', 'privacy_comment' => isset($aVals['privacy_comment']) ? $aVals['privacy_comment'] : '0', 'time_stamp' => PHPFOX_TIME, 'module_id' => isset($aVals['callback_module']) ? $aVals['callback_module'] : null, 'item_id' => isset($aVals['callback_item_id']) ? (int) $aVals['callback_item_id'] : '0'));
         $aAlbum = $this->database()->select('*')->from(Phpfox::getT('music_album'))->where('album_id = ' . (int) $iAlbumId)->execute('getSlaveRow');
         $this->database()->insert(Phpfox::getT('music_album_text'), array('album_id' => $iAlbumId));
         if ($aVals['privacy'] == '4') {
             // Phpfox::getService('privacy.process')->add('music_album', $iAlbumId, (isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array()));
         }
     }
     Phpfox::getService('ban')->checkAutomaticBan($aVals['title']);
     $aInsert = array('view_id' => Phpfox::getUserParam('music.music_song_approval') ? '1' : '0', 'privacy' => isset($aVals['privacy']) ? $aVals['privacy'] : '0', 'privacy_comment' => isset($aVals['privacy_comment']) ? $aVals['privacy_comment'] : '0', 'album_id' => $iAlbumId, 'genre_id' => isset($aVals['genre_id']) ? (int) $aVals['genre_id'] : '0', 'user_id' => Phpfox::getUserId(), 'title' => Phpfox::getLib('parse.input')->clean($aVals['title'], 255), 'description' => isset($aVals['status_info']) ? Phpfox::getLib('parse.input')->clean($aVals['status_info'], 255) : null, 'explicit' => isset($aVals['explicit']) && $aVals['explicit'] ? 1 : 0, 'time_stamp' => PHPFOX_TIME, 'module_id' => isset($aVals['callback_module']) ? $aVals['callback_module'] : null, 'item_id' => isset($aVals['callback_item_id']) ? (int) $aVals['callback_item_id'] : '0');
     $iId = $this->database()->insert($this->_sTable, $aInsert);
     if (!$iId) {
         return false;
     }
     $sFileName = Phpfox::getLib('file')->upload('mp3', Phpfox::getParam('music.dir'), $iId);
     $sDuration = null;
     if (file_exists(PHPFOX_DIR_LIB . 'getid3' . PHPFOX_DS . 'getid3' . PHPFOX_DS . 'getid3.php')) {
         // Temp. disable error reporting
         Phpfox_Error::skip(true);
         require_once PHPFOX_DIR_LIB . 'getid3' . PHPFOX_DS . 'getid3' . PHPFOX_DS . 'getid3.php';
         $oGetId3 = new getID3();
         $aMetaData = $oGetId3->analyze(Phpfox::getParam('music.dir') . sprintf($sFileName, ''));
         if (isset($aMetaData['playtime_string'])) {
             $sDuration = $aMetaData['playtime_string'];
         }
     }
     $aInsert['song_id'] = $iId;
     $aInsert['duration'] = $sDuration;
     $aInsert['song_path'] = $sFileName;
     $aInsert['full_name'] = $sFileName;
     $aInsert['is_featured'] = 0;
     $aInsert['user_name'] = Phpfox::getUserBy('user_name');
     // Return back error reporting
     Phpfox_Error::skip(false);
     $this->database()->update($this->_sTable, array('song_path' => $sFileName, 'server_id' => Phpfox::getLib('request')->getServer('PHPFOX_SERVER_ID'), 'duration' => $sDuration), 'song_id = ' . (int) $iId);
     // Update user space usage
     if (!Phpfox::getUserParam('music.music_song_approval')) {
         Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'music', filesize(Phpfox::getParam('music.dir') . sprintf($sFileName, '')));
     }
     if ($aVals['privacy'] == '4') {
         Phpfox::getService('privacy.process')->add('music_song', $iId, isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array());
     }
     $aCallback = null;
     if (!empty($aVals['callback_module']) && Phpfox::hasCallback($aVals['callback_module'], 'uploadSong')) {
         $aCallback = Phpfox::callback($aVals['callback_module'] . '.uploadSong', $aVals['callback_item_id']);
     }
     if ($iAlbumId > 0) {
         if (!Phpfox::getUserParam('music.music_song_approval')) {
             $this->database()->updateCounter('music_album', 'total_track', 'album_id', $iAlbumId);
             Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->callback($aCallback)->add('music_album', $iId, $aAlbum['privacy'], isset($aAlbum['privacy_comment']) ? (int) $aAlbum['privacy_comment'] : 0, isset($aVals['callback_item_id']) ? (int) $aVals['callback_item_id'] : '0') : null;
         }
     } else {
         if (!Phpfox::getUserParam('music.music_song_approval')) {
             Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->callback($aCallback)->add('music_song', $iId, $aVals['privacy'], isset($aVals['privacy_comment']) ? (int) $aVals['privacy_comment'] : 0, isset($aVals['callback_item_id']) ? (int) $aVals['callback_item_id'] : '0') : null;
         }
     }
     if (!Phpfox::getUserParam('music.music_song_approval')) {
         Phpfox::getService('user.activity')->update(Phpfox::getUserId(), 'music_song');
     }
     // plugin call
     if ($sPlugin = Phpfox_Plugin::get('music.service_process_upload__end')) {
         eval($sPlugin);
     }
     return $aInsert;
 }
Пример #5
0
 private function _check($sDestination)
 {
     if (!file_exists($sDestination)) {
         $this->_debug(Phpfox::getPhrase('video.unable_to_convert_video'));
         if (!empty($this->_sLastLineCode)) {
             Phpfox_Error::set($this->_sLastLineCode);
         }
         return Phpfox_Error::set(Phpfox::getPhrase('video.unable_to_convert_video'));
     }
     // Temp. disable error reporting
     Phpfox_Error::skip(true);
     require_once PHPFOX_DIR_LIB . 'getid3' . PHPFOX_DS . 'getid3' . PHPFOX_DS . 'getid3.php';
     $oGetId3 = new getID3();
     $aMetaData = $oGetId3->analyze($sDestination);
     // Return back error reporting
     Phpfox_Error::skip(false);
     if (isset($aMetaData['error']) && count($aMetaData['error'])) {
         if (!empty($this->_sLastLineCode)) {
             Phpfox_Error::set($this->_sLastLineCode);
         }
         return Phpfox_Error::set(implode('<br />', array_map('ucfirst', $aMetaData['error'])));
     }
     return true;
 }
Пример #6
0
 /**
  * Checks if path is writable
  *
  * @param string $sPath Path to file or directory
  * @param bool $bForce If set to TRUE we will disable error reporting and force a check on the file/folder
  * @return boolean If file/folder is writable we return TRUE otherwise we return FALSE
  */
 public function isWritable($sPath, $bForce = false)
 {
     clearstatcache();
     if ($bForce === false) {
         if (!is_writable($sPath)) {
             if (!stristr(PHP_OS, "win")) {
                 return false;
             }
         }
     }
     if ($bForce === true) {
         Phpfox_Error::skip(true);
     }
     /**
      * Checking if writable on windows OS
      */
     if (stristr(PHP_OS, "win") || $bForce === true) {
         /**
          * need to check whether we can really create files in this directory or not
          */
         if (is_dir($sPath)) {
             /**
              * Trying to create a new file
              */
             $fp = @fopen($sPath . PHPFOX_DS . 'win-test.txt', 'w');
             if (!$fp) {
                 if ($bForce === true) {
                     Phpfox_Error::skip(false);
                 }
                 return false;
             }
             if (!@fwrite($fp, 'test')) {
                 if ($bForce === true) {
                     Phpfox_Error::skip(false);
                 }
                 return false;
             }
             fclose($fp);
             /**
              * clean up after ourselves
              */
             if (file_exists($sPath . 'win-test.txt')) {
                 unlink($sPath . 'win-test.txt');
             }
         } else {
             if (!file_exists($sPath)) {
                 if ($bForce === true) {
                     Phpfox_Error::skip(false);
                 }
                 return false;
             }
             $sContent = @file_get_contents($sPath);
             if (!($fp = @fopen($sPath, 'w'))) {
                 if ($bForce === true) {
                     Phpfox_Error::skip(false);
                 }
                 return false;
             }
             if (!@fwrite($fp, $sContent)) {
                 if ($bForce === true) {
                     Phpfox_Error::skip(false);
                 }
                 return false;
             }
             fclose($fp);
         }
     }
     if ($bForce === true) {
         Phpfox_Error::skip(false);
     }
     return true;
 }
Пример #7
0
 public function getLink($sUrl)
 {
     if (substr($sUrl, 0, 7) != 'http://' && substr($sUrl, 0, 8) != 'https://') {
         $sUrl = 'http://' . $sUrl;
     }
     $aParts = parse_url($sUrl);
     if (!isset($aParts['host'])) {
         return Phpfox_Error::set(Phpfox::getPhrase('link.not_a_valid_link'));
     }
     $aReturn = array();
     $oVideo = json_decode(Phpfox::getLib('request')->send('http://api.embed.ly/1/oembed?format=json&maxwidth=400&url=' . urlencode($sUrl), array(), 'GET', $_SERVER['HTTP_USER_AGENT']));
     // http://www.phpfox.com/tracker/view/15305/
     if (!isset($oVideo->thumbnail_url)) {
         if (preg_match('/facebook/i', $sUrl)) {
             $aRegexes = array('/https?:\\/\\/www\\.facebook\\.com\\/v\\/([0-9]+)/i', '/https?:\\/\\/www\\.facebook\\.com\\/.*\\?v=([0-9]+)/i', '/https?:\\/\\/www\\.facebook\\.com\\/video\\/embed\\?video_id=([0-9]+)/i');
             foreach ($aRegexes as $sRegex) {
                 if (preg_match($sRegex, $sUrl, $aMatches)) {
                     $iId = $aMatches[1];
                 }
             }
             $oThumbnail = json_decode(Phpfox::getLib('request')->send('https://graph.facebook.com/' . $iId . '/picture?redirect=false', array(), 'GET', $_SERVER['HTTP_USER_AGENT']));
             $oVideo->thumbnail_url = $oThumbnail->data->url;
             $oVideo->type = 'video';
             $oVideo->html = '<iframe src="https://www.facebook.com/video/embed?video_id=' . $iId . '" width="400" height="300" frameborder="0"></iframe>';
         }
     }
     // END
     // http://embed.ly/docs/embed/api/endpoints/1/oembed => object->photo does not exist as response
     if (isset($oVideo->provider_url) || isset($oVideo->photo)) {
         $aReturn = array('link' => $sUrl, 'title' => isset($oVideo->title) ? strip_tags($oVideo->title) : '', 'description' => isset($oVideo->description) ? strip_tags($oVideo->description) : '', 'default_image' => $oVideo->type == 'photo' ? $oVideo->url : (isset($oVideo->thumbnail_url) ? $oVideo->thumbnail_url : ''), 'embed_code' => $oVideo->type == 'video' ? $oVideo->html : '');
         return $aReturn;
     }
     $aParseBuild = array();
     $sContent = Phpfox::getLib('request')->send($sUrl, array(), 'GET', $_SERVER['HTTP_USER_AGENT']);
     preg_match_all('/<(meta|link)(.*?)>/i', $sContent, $aRegMatches);
     if (isset($aRegMatches[2])) {
         foreach ($aRegMatches as $iKey => $aMatch) {
             if ($iKey !== 2) {
                 continue;
             }
             foreach ($aMatch as $sLine) {
                 $sLine = rtrim($sLine, '/');
                 $sLine = trim($sLine);
                 preg_match('/(property|name|rel)=("|\')(.*?)("|\')/ise', $sLine, $aType);
                 if (count($aType) && isset($aType[3])) {
                     $sType = $aType[3];
                     preg_match('/(content|type)=("|\')(.*?)("|\')/i', $sLine, $aValue);
                     if (count($aValue) && isset($aValue[3])) {
                         if ($sType == 'alternate') {
                             $sType = $aValue[3];
                             preg_match('/href=("|\')(.*?)("|\')/i', $sLine, $aHref);
                             if (isset($aHref[2])) {
                                 $aValue[3] = $aHref[2];
                             }
                         }
                         $aParseBuild[$sType] = $aValue[3];
                     }
                 }
             }
         }
         if (isset($aParseBuild['og:title'])) {
             $aReturn['link'] = $sUrl;
             $aReturn['title'] = $aParseBuild['og:title'];
             $aReturn['description'] = isset($aParseBuild['og:description']) ? $aParseBuild['og:description'] : '';
             $aReturn['default_image'] = isset($aParseBuild['og:image']) ? $aParseBuild['og:image'] : '';
             if (isset($aParseBuild['application/json+oembed'])) {
                 $oJson = json_decode(Phpfox::getLib('request')->send($aParseBuild['application/json+oembed'], array(), 'GET', $_SERVER['HTTP_USER_AGENT']));
                 if (isset($oJson->html)) {
                     $aReturn['embed_code'] = $oJson->html;
                 }
             }
             return $aReturn;
         }
     }
     $sContent = Phpfox::getLib('request')->send($sUrl, array(), 'GET', $_SERVER['HTTP_USER_AGENT'], null, true);
     if (function_exists('mb_convert_encoding')) {
         $sContent = mb_convert_encoding($sContent, 'HTML-ENTITIES', "UTF-8");
     }
     $aReturn['link'] = $sUrl;
     Phpfox_Error::skip(true);
     $oDoc = new DOMDocument();
     $oDoc->loadHTML($sContent);
     Phpfox_Error::skip(false);
     if (($oTitle = $oDoc->getElementsByTagName('title')->item(0)) && !empty($oTitle->nodeValue)) {
         $aReturn['title'] = strip_tags($oTitle->nodeValue);
     }
     if (empty($aReturn['title'])) {
         if (preg_match('/^(.*?)\\.(jpg|png|jpeg|gif)$/i', $sUrl, $aImageMatches)) {
             return array('link' => $sUrl, 'title' => '', 'description' => '', 'default_image' => $sUrl, 'embed_code' => '');
         }
         return Phpfox_Error::set(Phpfox::getPhrase('link.not_a_valid_link_unable_to_find_a_title'));
     }
     $oXpath = new DOMXPath($oDoc);
     $oMeta = $oXpath->query("//meta[@name='description']")->item(0);
     if (method_exists($oMeta, 'getAttribute')) {
         $sMeta = $oMeta->getAttribute('content');
         if (!empty($sMeta)) {
             $aReturn['description'] = strip_tags($sMeta);
         }
     }
     $aImages = array();
     $oMeta = $oXpath->query("//meta[@property='og:image']")->item(0);
     if (method_exists($oMeta, 'getAttribute')) {
         $aReturn['default_image'] = strip_tags($oMeta->getAttribute('content'));
         $aImages[] = strip_tags($oMeta->getAttribute('content'));
     }
     $oMeta = $oXpath->query("//link[@rel='image_src']")->item(0);
     if (method_exists($oMeta, 'getAttribute')) {
         if (empty($aReturn['default_image'])) {
             $aReturn['default_image'] = strip_tags($oMeta->getAttribute('href'));
         }
         $aImages[] = strip_tags($oMeta->getAttribute('href'));
     }
     if (!isset($aReturn['default_image'])) {
         $oMeta = $oXpath->query("//meta[@itemprop='image']")->item(0);
         if (method_exists($oMeta, 'getAttribute')) {
             $aReturn['default_image'] = strip_tags($oMeta->getAttribute('content'));
             if (strpos($aReturn['default_image'], $sUrl) === false) {
                 $aReturn['default_image'] = $sUrl . '/' . $aReturn['default_image'];
             }
         }
     }
     if (!isset($aReturn['default_image'])) {
         $oImages = $oDoc->getElementsByTagName('img');
         $iIteration = 0;
         foreach ($oImages as $oImage) {
             $sImageSrc = $oImage->getAttribute('src');
             if (substr($sImageSrc, 0, 7) != 'http://' && substr($sImageSrc, 0, 1) != '/') {
                 continue;
             }
             if (substr($sImageSrc, 0, 2) == '//') {
                 continue;
             }
             $iIteration++;
             if (substr($sImageSrc, 0, 1) == '/') {
                 $sImageSrc = 'http://' . $aParts['host'] . $sImageSrc;
             }
             if ($iIteration === 1 && empty($aReturn['default_image'])) {
                 $aReturn['default_image'] = strip_tags($sImageSrc);
             }
             if ($iIteration > 10) {
                 break;
             }
             $aImages[] = strip_tags($sImageSrc);
         }
     }
     if (count($aImages)) {
         $aReturn['images'] = $aImages;
     }
     $oLink = $oXpath->query("//link[@type='text/xml+oembed']")->item(0);
     if (method_exists($oLink, 'getAttribute')) {
         $aXml = Phpfox::getLib('xml.parser')->parse(Phpfox::getLib('request')->send($oLink->getAttribute('href'), array(), 'GET', $_SERVER['HTTP_USER_AGENT']));
         if (isset($aXml['html'])) {
             $aReturn['embed_code'] = $aXml['html'];
         }
     }
     return $aReturn;
 }
Пример #8
0
	/**
	 * Try to find the full path of where we are currently located based on the relative position
	 * we are allowed to access on the FTP server.
	 *
	 * @return mixed FALSE if we cannot find where we are, STRING if we can; which is the full path to where we are
	 */
	public function getPath()
	{
		Phpfox_Error::skip(true);
		if (ftp_chdir($this->_oFtp, PHPFOX_DIR))
		{
			return '';
		}
		Phpfox_Error::skip(false);
		
		$sCurrentDirectory = ftp_pwd($this->_oFtp);
		
		$aCache = array();
		$aParts = explode(PHPFOX_DS, PHPFOX_DIR);
		foreach ($aParts as $sPart)
		{
			if (empty($sPart))
			{
				continue;
			}
			
			$aCache[$sPart] = true;
		}		
		
		$sBase = '';
		$aList = ftp_nlist($this->_oFtp, '.');
		foreach ($aList as $sList)
		{
			if ($sList == '.' || $sList == '..')
			{
				continue;
			}

            $sList = trim($sList, '.');
            $sList = trim($sList, '/');
            $sList = trim($sList, '\/');
			
			if (isset($aCache[$sList]))
			{
				$sBase = $sList;
				break;
			}
		}		
		
		if (!empty($sBase))
		{
			$aBaseParts = explode($sBase, PHPFOX_DIR);			
			
			return PHPFOX_DS . $sBase . $aBaseParts[1];
		}
		
		return false;
	}
Пример #9
0
 /**
  * Text we need to parse, usually text added via a <textarea>.
  *
  * @param string $sTxt is the string we need to parse
  * @return string Parsed string
  */
 public function parse($sTxt)
 {
     if (empty($sTxt)) {
         return $sTxt;
     }
     if ($sPlugin = Phpfox_Plugin::get('phpfox_parse_output_parse__start')) {
         eval($sPlugin);
     }
     $sTxt = ' ' . $sTxt;
     if (!Phpfox::getParam('core.allow_html')) {
         $oFilterBbcode = Phpfox::getLib('parse.bbcode');
         if (Phpfox::isModule('emoticon')) {
             $sTxt = Phpfox::getService('emoticon')->parse($sTxt);
         }
         $sTxt = $oFilterBbcode->preParse($sTxt);
         $sAllowedTags = '<p><b><i><u><br><br />';
         $sTxt = strip_tags($sTxt, $sAllowedTags);
         // Add breaks without messing up HTML
         $sTxt = str_replace("\n", "[br]", $sTxt);
         $sTxt = preg_replace('/<(.*?)>/ise', "'<'. stripslashes(str_replace('[br]', '', '\\1')) .'>'", $sTxt);
         $sTxt = str_replace("[br]", "<br />", $sTxt);
         // Parse BBCode
         $sTxt = $oFilterBbcode->parse($sTxt);
     }
     $sTxt = Phpfox::getService('ban.word')->clean($sTxt);
     /*
     if (Phpfox::getParam('core.xhtml_valid'))
     {
     	$sTxt = Phpfox::getLib('parse.format')->validXhtml($sTxt);
     }
     */
     $sTxt = $this->parseUrls($sTxt);
     $sTxt = preg_replace_callback('/<object(.*?)>(.*?)<\\/object>/is', array($this, '_embedWmode'), $sTxt);
     // $sTxt = preg_replace_callback('/<iframe(.*?)>(.*?)<\/iframe>/is', array($this, '_embedWmode'), $sTxt);
     if (Phpfox::getParam('core.enable_html_purifier') && file_exists(PHPFOX_DIR_LIB . 'htmlpurifier/HTMLPurifier.auto.php')) {
         static $purifier = null;
         Phpfox_Error::skip(true);
         if ($purifier === null) {
             require_once PHPFOX_DIR_LIB . 'htmlpurifier/HTMLPurifier.auto.php';
             $config = HTMLPurifier_Config::createDefault();
             if (file_exists(PHPFOX_DIR_SETTING . 'htmlpurifier.sett.php')) {
                 require_once PHPFOX_DIR_SETTING . 'htmlpurifier.sett.php';
             } else {
                 require_once PHPFOX_DIR_SETTING . 'htmlpurifier.sett.php.new';
             }
             $config->set('Attr.AllowedRel', array('nofollow'));
             $config->set('Attr.AllowedFrameTargets', array('_blank'));
             $purifier = new HTMLPurifier($config);
         }
         $sTxt = $purifier->purify($sTxt);
         Phpfox_Error::skip(false);
     }
     $sTxt = preg_replace_callback('/\\[PHPFOX_PHRASE\\](.*?)\\[\\/PHPFOX_PHRASE\\]/i', array($this, '_getPhrase'), $sTxt);
     if (Phpfox::getParam('core.resize_images')) {
         $sTxt = preg_replace_callback('/<img(.*?)>/i', array($this, '_fixImageWidth'), $sTxt);
     }
     if (Phpfox::getParam('tag.enable_hashtag_support')) {
         $sTxt = $this->replaceHashTags($sTxt);
     }
     return $sTxt;
 }
Пример #10
0
 /**
  * Uploads the file to Rackspace server.
  *
  * @param string $sFile Full path to where the file is located.
  * @param string $sName Optional name of the file once it is uploaded. By default we just use the original file name.
  * @return bool We only return a bool false if we were not able to upload the item.
  */
 public function put($sFile, $sName = null)
 {
     $this->connect();
     Phpfox_Error::skip(true);
     if (empty($sName)) {
         $sName = str_replace("\\", '/', str_replace(PHPFOX_DIR, '', $sFile));
     }
     $object = $this->_oContainer->create_object($sName);
     try {
         $object->load_from_filename($sFile);
     } catch (Exception $hException) {
         Phpfox_Error::trigger($hException->getMessage());
     }
     $this->_bIsUploaded = true;
     if (Phpfox::getParam('core.keep_files_in_server') == false) {
         $oSess = Phpfox::getLib('session');
         $aFiles = $oSess->get('deleteFiles');
         if (is_array($aFiles)) {
             $aFiles[] = $sFile;
         } else {
             $aFiles = array($sFile);
         }
         $oSess->set('deleteFiles', $aFiles);
     }
     Phpfox_Error::skip(false);
     return true;
 }
Пример #11
0
	public function getLink($sUrl)
	{
		if (substr($sUrl, 0, 7) != 'http://')
		{
			$sUrl = 'http://' . $sUrl;
		}
			
		$aParts = parse_url($sUrl);	
		
		if (!isset($aParts['host']))
		{
			return Phpfox_Error::set('Not a valid link.');
		}
		
		$aReturn = array();
		
		$sCacheId = $this->cache()->set('api_embed_ly');
		$aSites = array();		
		if (!($aSites = $this->cache()->get($sCacheId)))
		{
			$aSites[] = '#http://.*myspace.com/video/.*#i';
			$oOutput = json_decode(Phpfox::getLib('request')->send('http://api.embed.ly/1/services/php', array(), 'GET', $_SERVER['HTTP_USER_AGENT']));
			if (!is_array($oOutput))
			{
				return Phpfox_Error::set('Unable to build api.embed.ly array of sites.');
			}
			foreach ($oOutput as $aOutput)
			{
				foreach ($aOutput->regex as $sRegex)
				{
					$aSites[] = $sRegex;
				}
			}

			$this->cache()->save($sCacheId, $aSites);
		}
		
		foreach ($aSites as $sSiteRegex)
		{		
			if (preg_match($sSiteRegex, $sUrl))
			{
				$oVideo = json_decode(Phpfox::getLib('request')->send('http://api.embed.ly/1/oembed?format=json&maxwidth=400&url=' . urlencode($sUrl), array(), 'GET', $_SERVER['HTTP_USER_AGENT']));
	
				if (isset($oVideo->provider_url))
				{
					$aReturn = array(
						'link' => $sUrl,
						'title' => strip_tags($oVideo->title),
						'description' => strip_tags($oVideo->description),
						'default_image' => $oVideo->thumbnail_url,
						'embed_code' => ($oVideo->type == 'video' ? $oVideo->html : '')
					);
					
					return $aReturn;
				}
			}
		}
		
		$sContent = Phpfox::getLib('request')->send($sUrl, array(), 'GET', $_SERVER['HTTP_USER_AGENT']);
		if( function_exists('mb_convert_encoding') )
      	{
      		$sContent = mb_convert_encoding($sContent, 'HTML-ENTITIES', "UTF-8");
      	}		
      	      	
      	$aReturn['link'] = $sUrl;
		
		Phpfox_Error::skip(true);
		$oDoc = new DOMDocument();
		$oDoc->loadHTML($sContent);
		Phpfox_Error::skip(false);
		
		if (($oTitle = $oDoc->getElementsByTagName('title')->item(0)) && !empty($oTitle->nodeValue))
		{
			$aReturn['title'] = strip_tags($oTitle->nodeValue);
		}
		
		if (empty($aReturn['title']))
		{
			return Phpfox_Error::set('Not a valid link. Unable to find a title.');
		}
		
		$oXpath = new DOMXPath($oDoc);	
		$oMeta = $oXpath->query("//meta[@name='description']")->item(0);
		if (method_exists($oMeta, 'getAttribute'))
		{
			$sMeta = $oMeta->getAttribute('content');
			if (!empty($sMeta))
			{
				$aReturn['description'] = strip_tags($sMeta);
			}
		}
		
		$aImages = array();		
		$oMeta = $oXpath->query("//meta[@property='og:image']")->item(0);
		if (method_exists($oMeta, 'getAttribute'))
		{			
			$aReturn['default_image'] = strip_tags($oMeta->getAttribute('content'));
			$aImages[] = strip_tags($oMeta->getAttribute('content'));
		}		
		
		$oMeta = $oXpath->query("//link[@rel='image_src']")->item(0);
		if (method_exists($oMeta, 'getAttribute'))
		{			
			if (empty($aReturn['default_image']))
			{
				$aReturn['default_image'] = strip_tags($oMeta->getAttribute('href'));
			}
			$aImages[] = strip_tags($oMeta->getAttribute('href'));
		}			
		
		if (!isset($aReturn['default_image']))
		{
			$oImages = $oDoc->getElementsByTagName('img');
			$iIteration = 0;
			foreach ($oImages as $oImage)
			{
				$sImageSrc = $oImage->getAttribute('src');
				
				if (substr($sImageSrc, 0, 7) != 'http://' && substr($sImageSrc, 0, 1) != '/')
				{
					continue;	
				}
				
				if (substr($sImageSrc, 0, 2) == '//')
				{
					continue;
				}
				
				$iIteration++;		
				
				if (substr($sImageSrc, 0, 1) == '/')
				{					
					$sImageSrc = 'http://' . $aParts['host'] . $sImageSrc;
				}			
				
				if ($iIteration === 1 && empty($aReturn['default_image']))
				{
					$aReturn['default_image'] = strip_tags($sImageSrc);
				}
				
				if ($iIteration > 10)
				{
					break;
				}
				
				$aImages[] = strip_tags($sImageSrc);
			}
		}
		
		if (count($aImages))
		{
			$aReturn['images'] = $aImages;
		}
		
		$oLink = $oXpath->query("//link[@type='text/xml+oembed']")->item(0);
		if (method_exists($oLink, 'getAttribute'))
		{	
			$aXml = Phpfox::getLib('xml.parser')->parse(Phpfox::getLib('request')->send($oLink->getAttribute('href'), array(), 'GET', $_SERVER['HTTP_USER_AGENT']));			
			if (isset($aXml['html']))
			{
				$aReturn['embed_code'] = $aXml['html'];	
			}
		}				
		
		return $aReturn;
	}
Пример #12
0
 /**
  * Garbage collecting.
  *
  * @param int $iMaxLifetime Define how long a session can exist on the server.
  * @return bool Always TRUE.
  */
 public function gc($iMaxLifetime)
 {
     Phpfox_Error::skip(true);
     foreach (glob($this->_sSavePath . $this->_sPrefix . '*') as $sFilename) {
         if (filemtime($sFilename) + $iMaxLifetime < time()) {
             @unlink($sFilename);
         }
     }
     Phpfox_Error::skip(false);
     return true;
 }
Пример #13
0
 /**
  * get link
  * @param $sUrl
  * @return array|bool
  */
 public function getLink($sUrl)
 {
     if (substr($sUrl, 0, 7) != 'http://' && substr($sUrl, 0, 8) != 'https://') {
         $sUrl = 'http://' . $sUrl;
     }
     $aParts = parse_url($sUrl);
     if (!isset($aParts['host'])) {
         return false;
     }
     $aReturn = array();
     $oVideo = json_decode(Phpfox::getLib('request')->send('http://api.embed.ly/1/oembed?format=json&maxwidth=400&url=' . urlencode($sUrl), array(), 'GET', $_SERVER['HTTP_USER_AGENT']));
     if (isset($oVideo->provider_url) && isset($oVideo->photo)) {
         $aReturn = array('link' => $sUrl, 'title' => isset($oVideo->title) ? strip_tags($oVideo->title) : '', 'description' => isset($oVideo->description) ? strip_tags($oVideo->description) : '', 'default_image' => $oVideo->type == 'photo' ? $oVideo->url : (isset($oVideo->thumbnail_url) ? $oVideo->thumbnail_url : ''), 'embed_code' => $oVideo->type == 'video' ? $oVideo->html : '');
         return $aReturn;
     }
     $aParseBuild = array();
     $sContent = Phpfox::getLib('request')->send($sUrl, array(), 'GET', $_SERVER['HTTP_USER_AGENT']);
     preg_match_all('/<(meta|link)(.*?)>/i', $sContent, $aRegMatches);
     if (isset($aRegMatches[2])) {
         foreach ($aRegMatches as $iKey => $aMatch) {
             if ($iKey !== 2) {
                 continue;
             }
             foreach ($aMatch as $sLine) {
                 $sLine = rtrim($sLine, '/');
                 $sLine = trim($sLine);
                 preg_match('/(property|name|rel)=("|\')(.*?)("|\')/ise', $sLine, $aType);
                 if (count($aType) && isset($aType[3])) {
                     $sType = $aType[3];
                     preg_match('/(content|type)=("|\')(.*?)("|\')/i', $sLine, $aValue);
                     if (count($aValue) && isset($aValue[3])) {
                         if ($sType == 'alternate') {
                             $sType = $aValue[3];
                             preg_match('/href=("|\')(.*?)("|\')/i', $sLine, $aHref);
                             if (isset($aHref[2])) {
                                 $aValue[3] = $aHref[2];
                             }
                         }
                         $aParseBuild[$sType] = $aValue[3];
                     }
                 }
             }
         }
         if (isset($aParseBuild['og:title'])) {
             $aReturn['link'] = $sUrl;
             $aReturn['title'] = $aParseBuild['og:title'];
             $aReturn['description'] = isset($aParseBuild['og:description']) ? $aParseBuild['og:description'] : '';
             $aReturn['default_image'] = isset($aParseBuild['og:image']) ? $aParseBuild['og:image'] : '';
             if (isset($aParseBuild['application/json+oembed'])) {
                 $oJson = json_decode(Phpfox::getLib('request')->send($aParseBuild['application/json+oembed'], array(), 'GET', $_SERVER['HTTP_USER_AGENT']));
                 if (isset($oJson->html)) {
                     $aReturn['embed_code'] = $oJson->html;
                 }
             }
             return $aReturn;
         }
     }
     $sContent = Phpfox::getLib('request')->send($sUrl, array(), 'GET', $_SERVER['HTTP_USER_AGENT'], null, true);
     if (function_exists('mb_convert_encoding')) {
         $sContent = mb_convert_encoding($sContent, 'HTML-ENTITIES', "UTF-8");
     }
     $aReturn['link'] = $sUrl;
     Phpfox_Error::skip(true);
     $oDoc = new DOMDocument();
     $oDoc->loadHTML($sContent);
     Phpfox_Error::skip(false);
     if (($oTitle = $oDoc->getElementsByTagName('title')->item(0)) && !empty($oTitle->nodeValue)) {
         $aReturn['title'] = strip_tags($oTitle->nodeValue);
     }
     if (empty($aReturn['title'])) {
         if (preg_match('/^(.*?)\\.(jpg|png|jpeg|gif)$/i', $sUrl, $aImageMatches)) {
             return array('link' => $sUrl, 'title' => '', 'description' => '', 'default_image' => $sUrl, 'embed_code' => '');
         }
         return false;
     }
     $oXpath = new DOMXPath($oDoc);
     $oMeta = $oXpath->query("//meta[@name='description']")->item(0);
     if (method_exists($oMeta, 'getAttribute')) {
         $sMeta = $oMeta->getAttribute('content');
         if (!empty($sMeta)) {
             $aReturn['description'] = strip_tags($sMeta);
         }
     }
     $aImages = array();
     $oMeta = $oXpath->query("//meta[@property='og:image']")->item(0);
     if (method_exists($oMeta, 'getAttribute')) {
         $aReturn['default_image'] = strip_tags($oMeta->getAttribute('content'));
         $aImages[] = strip_tags($oMeta->getAttribute('content'));
     }
     $oMeta = $oXpath->query("//link[@rel='image_src']")->item(0);
     if (method_exists($oMeta, 'getAttribute')) {
         if (empty($aReturn['default_image'])) {
             $aReturn['default_image'] = strip_tags($oMeta->getAttribute('href'));
         }
         $aImages[] = strip_tags($oMeta->getAttribute('href'));
     }
     if (!isset($aReturn['default_image'])) {
         $oMeta = $oXpath->query("//meta[@itemprop='image']")->item(0);
         if (method_exists($oMeta, 'getAttribute')) {
             $aReturn['default_image'] = strip_tags($oMeta->getAttribute('content'));
             if (strpos($aReturn['default_image'], $sUrl) === false) {
                 $aReturn['default_image'] = $sUrl . '/' . $aReturn['default_image'];
             }
         }
     }
     if (!isset($aReturn['default_image'])) {
         $oImages = $oDoc->getElementsByTagName('img');
         $iIteration = 0;
         foreach ($oImages as $oImage) {
             $sImageSrc = $oImage->getAttribute('src');
             if (substr($sImageSrc, 0, 7) != 'http://' && substr($sImageSrc, 0, 1) != '/') {
                 continue;
             }
             if (substr($sImageSrc, 0, 2) == '//') {
                 continue;
             }
             $iIteration++;
             if (substr($sImageSrc, 0, 1) == '/') {
                 $sImageSrc = 'http://' . $aParts['host'] . $sImageSrc;
             }
             if ($iIteration === 1 && empty($aReturn['default_image'])) {
                 $aReturn['default_image'] = strip_tags($sImageSrc);
             }
             if ($iIteration > 10) {
                 break;
             }
             $aImages[] = strip_tags($sImageSrc);
         }
     }
     if (count($aImages)) {
         $aReturn['images'] = $aImages;
     }
     $oLink = $oXpath->query("//link[@type='text/xml+oembed']")->item(0);
     if (method_exists($oLink, 'getAttribute')) {
         $aXml = Phpfox::getLib('xml.parser')->parse(Phpfox::getLib('request')->send($oLink->getAttribute('href'), array(), 'GET', $_SERVER['HTTP_USER_AGENT']));
         if (isset($aXml['html'])) {
             $aReturn['embed_code'] = $aXml['html'];
         }
     }
     return $aReturn;
 }