/**
  * Handles a [video] tag. Displays a movie.
  *
  * @param	string	The code to display
  *
  * @return	string	HTML representation of the tag.
  */
 function handle_bbcode_video($url, $option)
 {
     global $vbulletin, $vbphrase, $show;
     static $providers = array();
     static $scraped = 0;
     $search = $replace = array();
     // Legacy Hook 'data_preparse_bbcode_video_start' Removed //
     if (!$providers) {
         $bbcodes = $vbulletin->db->query_read_slave("\n\t\t\t\tSELECT\n\t\t\t\t\tprovider, url, regex_url, regex_scrape, tagoption\n\t\t\t\tFROM " . TABLE_PREFIX . "bbcode_video\n\t\t\t\tORDER BY priority\n\t\t\t");
         while ($bbcode = $vbulletin->db->fetch_array($bbcodes)) {
             $providers["{$bbcode['tagoption']}"] = $bbcode;
         }
     }
     if (!empty($providers)) {
         $match = false;
         foreach ($providers as $provider) {
             $addcaret = $provider['regex_url'][0] != '^' ? '^' : '';
             if (preg_match('#' . $addcaret . $provider['regex_url'] . '#si', $url, $match)) {
                 break;
             }
         }
         if ($match) {
             if (!$provider['regex_scrape'] and $match[1]) {
                 return '[video=' . $provider['tagoption'] . ';' . $match[1] . ']' . $url . '[/video]';
             } else {
                 if ($provider['regex_scrape'] and $vbulletin->options['bbcode_video_scrape'] > 0 and $scraped < $vbulletin->options['bbcode_video_scrape']) {
                     require_once DIR . '/includes/functions_file.php';
                     $result = fetch_body_request($url);
                     if (preg_match('#' . $provider['regex_scrape'] . '#si', $result, $scrapematch)) {
                         return '[video=' . $provider['tagoption'] . ';' . $scrapematch[1] . ']' . $url . '[/video]';
                     }
                     $scraped++;
                 }
             }
         }
     }
     return '[video]' . $url . '[/video]';
 }
Exemple #2
0
	protected function saveData($view)
	{
		if ($this->data_saved)
		{
			return true;
		}
		$this->data_saved = true;

		if (!$this->content->canEdit() AND !$this->content->canPublish() )
		{
			return $vb_phrase['no_edit_permissions'];
		}

		require_once DIR . '/includes/functions.php';
		// collect error messages
		$errors = array();
		vB::$vbulletin->input->clean_array_gpc('p', array(
			'do'               => vB_Input::TYPE_STR,
			'cms_node_title'   => vB_Input::TYPE_STR,
			'cms_node_url'     => vB_Input::TYPE_STR,
			'message'          => vB_Input::TYPE_STR,
			'url'              => vB_Input::TYPE_NOHTML,
			'title'            => vB_Input::TYPE_NOHTML,
			'setpublish'       => vB_Input::TYPE_UINT,
			'publishdate'      => vB_Input::TYPE_UINT,
			'html_title'       => vB_Input::TYPE_NOHTML,
			'publicpreview'    => vB_Input::TYPE_UINT,
			'new_parentid'     => vB_Input::TYPE_UINT,
			'comments_enabled' => vB_Input::TYPE_UINT,
			'wysiwyg'          => vB_Input::TYPE_BOOL,
			'parseurl'         => vB_Input::TYPE_BOOL,
			'posthash'         => vB_Input::TYPE_NOHTML,
			'poststarttime'    => vB_Input::TYPE_UINT,
			'htmlstate'        => vB_Input::TYPE_NOHTML,
		));

		($hook = vBulletinHook::fetch_hook('vbcms_article_save_start')) ? eval($hook) : false;
		$dm = $this->content->getDM();
		$dm->set('contentid', $this->content->getId());

		if ($this->content->canEdit())
		{
			// get pagetext
			$pagetext = vB::$vbulletin->GPC['message'];
			$html_title = vB::$vbulletin->GPC['html_title'];
			$title = vB::$vbulletin->GPC['title'];

			// unwysiwygify the incoming data
			if (vB::$vbulletin->GPC['wysiwyg'])
			{
				$html_parser = new vBCms_WysiwygHtmlParser(vB::$vbulletin);
				$pagetext = $html_parser->parse($pagetext);
			}

			$dm->info['parseurl'] = true;
			$dm->set('pagetext', $pagetext);

			if ($title)
			{
				$dm->set('title', $pagetext);
			}

			$bbcodesearch = array();

			$video_location = stripos($pagetext, '[video');

			$found_image = false;
			// populate the preview image field with [img] if we can find one
			if (($i = stripos($pagetext, '[IMG]')) !== false and ($j = stripos($pagetext, '[/IMG]')) AND $j > $i)
			{
				$previewimage = htmlspecialchars_uni(substr($pagetext, $i+5, $j - $i - 5));
				$image_location = $i;
				if ($size = @getimagesize($previewimage))
				{
					$dm->set('previewimage', $previewimage);
					$dm->set('imagewidth', $size[0]);
					$dm->set('imageheight', $size[1]);
					$bbcodesearch[] = substr($pagetext, $i, $j + 6);
					$found_image = true;
				}
			}
			// or populate the preview image field with [attachment] if we can find one
			if (!$found_image)
			{
				$i = stripos($pagetext, "[ATTACH=CONFIG]");
				$j = stripos($pagetext, '[/ATTACH]');

				if ($j !== false)
				{
					if ($i === false)
					{
						$i = stripos($pagetext, "[ATTACH]");

						if ($i !== false AND ($i > $j))
						{
							$attachmentid = substr($pagetext, $i + 15, $j - $i - 15);
							$found_image = $this->getAttachData($attachmentid, $dm, $bbcodesearch);
						}
					}
					else if ($i > $j)
					{
						$attachmentid = substr($pagetext, $i + 15, $j - $i - 15);
						$found_image = $this->getAttachData($attachmentid, $dm, $bbcodesearch);
					}

				}
			}

			if (!$found_image AND $this->content->canDownload())
			{
				require_once(DIR . '/packages/vbattach/attach.php');
				$attach = new vB_Attach_Display_Content(vB::$vbulletin, 'vBCms_Article');
				$attachments = $attach->fetch_postattach(0, $this->content->getNodeId(), $this->content->getUserId());

				if (!empty($attachments))
				{
					foreach($attachments as $attachment)
					{
						if ($attachment['hasthumbnail'])
						{
							$found_image = $this->getAttachData($attachment['attachmentid'], $dm, $bbcodesearch);
							if ($found_image)
							{
								break;
							}
						}
					}
				}
			}

			// if there are no images in the article body, make sure we unset the preview in the db
			if (!$found_image )
			{
				$dm->set('previewimage', '');
				$dm->set('imagewidth', 0);
				$dm->set('imageheight', 0);
				$image_location = intval($video_location) + 1;
			}
			$parseurl = false;
			$providers = $search = $replace = $previewvideo = array();
			($hook = vBulletinHook::fetch_hook('data_preparse_bbcode_video_start')) ? eval($hook) : false;

			// Convert video bbcode with no option
			if ((($video_location !== false) AND (intval($video_location) < intval($image_location))) OR $parseurl)
			{
				if (!$providers)
				{
					$bbcodes = vB::$db->query_read_slave("
						SELECT
						provider, url, regex_url, regex_scrape, tagoption
					FROM " . TABLE_PREFIX . "bbcode_video
					ORDER BY priority
				");
					while ($bbcode = vB::$db->fetch_array($bbcodes))
					{
						$providers["$bbcode[tagoption]"] = $bbcode;
					}
				}

				$scraped = 0;
				if (!empty($providers) AND preg_match_all('#\[video[^\]]*\](.*?)\[/video\]#si', $pagetext, $matches))
				{
					foreach ($matches[1] AS $key => $url)
					{
						$match = false;
						foreach ($providers AS $provider)
						{
							$addcaret = ($provider['regex_url'][0] != '^') ? '^' : '';
							if (preg_match('#' . $addcaret . $provider['regex_url'] . '#si', $url, $match))
							{
								break;
							}
						}
						if ($match)
						{
							if (!$provider['regex_scrape'] AND $match[1])
							{
								$previewvideo['provider'] = $provider['tagoption'];
								$previewvideo['code'] = $match[1];
								$previewvideo['url'] = $url;
								$bbcodesearch[] = $matches[0][$key];
								break;
							}
							else if ($provider['regex_scrape'] AND vB::$vbulletin->options['bbcode_video_scrape'] > 0 AND $scraped < vB::$vbulletin->options['bbcode_video_scrape'])
							{
								require_once(DIR . '/includes/functions_file.php');
								$result = fetch_body_request($url);
								if (preg_match('#' . $provider['regex_scrape'] . '#si', $result, $scrapematch))
								{
									$previewvideo['provider'] = $provider['tagoption'];
									$previewvideo['code'] = $scrapematch[1];
									$previewvideo['url'] = $url;
									$bbcodesearch[] = $matches[0][$key];
									break;
								}
								$scraped++;
							}
						}
					}
				}
			}

			$htmlstate = vB::$vbulletin->GPC_exists['htmlstate'] ? vB::$vbulletin->GPC['htmlstate']
				: $this->content->getHtmlState();

			// Try to populate previewvideo html
			if ($previewvideo)
			{
				$templater = vB_Template::create('bbcode_video');
				$templater->register('url', $previewvideo['url']);
				$templater->register('provider', $previewvideo['provider']);
				$templater->register('code', $previewvideo['code']);
				$dm->set('previewvideo', $templater->render());
				$dm->set('previewimage', '');
				$dm->set('imagewidth', 0);
				$dm->set('imageheight', 0);
				$image_location = -1;
			}
			else
			{
				$dm->set('previewvideo', '');
			}

				}

		if ($this->content->canPublish())
		{
			$old_sectionid = $this->content->getParentId();

			//set the values, for the dm and update the content.
			if ( vB::$vbulletin->GPC_exists['new_parentid'] AND intval(vB::$vbulletin->GPC['new_parentid']))
			{
				vBCms_ContentManager::moveSection(array($this->content->getNodeId()), vB::$vbulletin->GPC['new_parentid']);
				$new_sectionid = vB::$vbulletin->GPC['new_parentid'];
			}

			if (vB::$vbulletin->GPC_exists['publicpreview'])
			{
				$dm->set('publicpreview', vB::$vbulletin->GPC['publicpreview']);
			}

			if (vB::$vbulletin->GPC_exists['comments_enabled'])
			{
				$dm->set('comments_enabled', vB::$vbulletin->GPC['comments_enabled']);
			}

			if (vB::$vbulletin->GPC_exists['setpublish'])
			{
				$dm->set('setpublish', vB::$vbulletin->GPC['setpublish']);
			}
		}

		if (vB::$vbulletin->GPC_exists['html_title'])
		{
			$dm->set('html_title', vB::$vbulletin->GPC['html_title']);
		}

		if (vB::$vbulletin->GPC_exists['url'])
		{
			$dm->set('url', vB::$vbulletin->GPC['url']);
		}

		if (vB::$vbulletin->GPC_exists['htmlstate'])
		{
			$dm->set('htmlstate', vB::$vbulletin->GPC['htmlstate']);
		}

		//We may have some processing to do for public preview. Let's see if comments
		// are enabled. We never enable them for sections, and they might be turned off globally.
		vB::$vbulletin->input->clean_array_gpc('r', array(
			'publicpreview' => TYPE_UINT));

		$success = $dm->saveFromForm($this->content->getNodeId());
		$this->changed = true;

		if ($dm->hasErrors())
		{
			$fieldnames = array(
				'html_title' => new vB_Phrase('vbcms', 'html_title'),
				'title' => new vB_Phrase('global', 'title')
			);

			$view->errors = $dm->getErrors(array_keys($fieldnames));
			$view->error_summary = self::getErrorSummary($dm->getErrors(array_keys($fieldnames)), $fieldnames);
			$view->status = $view->error_view->title;
		}
		else
		{
			$view->status = new vB_Phrase('vbcms', 'content_saved');
			$this->cleanContentCache();

			// Make sure the posthash is valid
			if (md5(vB::$vbulletin->GPC['poststarttime'] . vB::$vbulletin->userinfo['userid'] . vB::$vbulletin->userinfo['salt']) == vB::$vbulletin->GPC['posthash'])
			{
				vB::$vbulletin->db->query_write("
					UPDATE " . TABLE_PREFIX . "attachment
					SET
						posthash = '',
						contentid = " . intval($this->content->getNodeId()) . "
					WHERE
						posthash = '" . vB::$vbulletin->db->escape_string(vB::$vbulletin->GPC['posthash']) . "'
							AND
						contenttypeid = " . intval(vB_Types::instance()->getContentTypeID("vBCms_Article")) . "
				");
			}

			// only publish to Facebook if we are going from not-published to published, and the date is in the past
			if (is_facebookenabled() AND $this->content->isPublished())
			{
				$message =  new vB_Phrase('posting', 'fbpublish_message_newarticle', vB::$vbulletin->options['bbtitle']);
				$fblink =  vBCms_Route_Content::getURL(array(
					'node' => $this->content->getUrlSegment(),
					'action' =>'view'
				));
				$fblink = str_ireplace('&amp;', '&', $fblink);
				publishtofacebook_newarticle($message, $this->content->getTitle(), $this->content->getPageText(), create_full_url($fblink));
			}
		}
		($hook = vBulletinHook::fetch_hook('vbcms_article_save_end')) ? eval($hook) : false;

		//invalidate the navigation cache.
		vB_Cache::instance()->event('sections_updated');
		vB_Cache::instance()->event('articles_updated');
		vB_Cache::instance()->event(array_merge($this->content->getCacheEvents(),
			array($this->content->getContentCacheEvent())));

		//Make sure comment count will be updated when a comment is posted
		if ($threadid = $this->content->getAssociatedThreadId())
		{
			vB_Cache::instance()->event("cms_comments_thread_$threadid");
		}
		vB_Cache::instance()->cleanNow();
		$this->content->reset();
		//reset the required information
		$this->content->requireInfo(vBCms_Item_Content::INFO_BASIC);
		$this->content->requireInfo(vBCms_Item_Content::INFO_CONTENT);
		$this->content->requireInfo(vBCms_Item_Content::INFO_CONFIG);
		$this->content->requireInfo(vBCms_Item_Content::INFO_NODE);
		$this->content->requireInfo(vBCms_Item_Content::INFO_PARENTS);
	}
	function pre_save($doquery = true)
	{
		if ($this->presave_called !== null)
		{
			return $this->presave_called;
		}

		if (!$this->condition)
		{
			if (!($blogid = $this->fetch_field('blogid')))
			{
				global $vbphrase;
				$this->error('invalidid', $vbphrase['blog'], $this->registry->options['contactuslink']);
				return false;
			}

			if (!($url = $this->fetch_field('url')))
			{
				$this->error('no_url_specified');
				return false;
			}

			if (!$this->fetch_field('state'))
			{
				$this->set('state', 'moderation');
			}
			if (!$this->fetch_field('dateline'))
			{
				$this->set('dateline', TIMENOW);
			}

			if (!$this->fetch_field('title') OR !$this->fetch_field('snippet'))
			{
				require_once(DIR . '/includes/functions_file.php');
				if ($bodyresult = fetch_body_request($url, 100000))
				{
					if (preg_match('#<head[^>]*>.*<title>(.*)</title>.*</head>.*<body(.*?)#siU', $bodyresult, $matches))
					{
						$body =& $matches[2];
						if (!$this->fetch_field('title'))
						{
							$this->set('title', $matches[1]);
						}
						else
						{
							$this->error('invalid_title_specified');
							return false;
						}

						if (!$this->fetch_field('snippet'))
						{
							if (preg_match('#(<a[^>]+href=(\'|")' . preg_quote($this->registry->options['bburl'], '#') . '\/blog(?:_callback)?.php\?b(?:logid)?=' . $blogid . '\\2[^>]*>(.*)</a>)#siU', $body, $matches))
							{
								$hash = md5(TIMENOW . SCRIPTPATH . SESSION_IDHASH . SESSION_HOST . vbrand(1, 1000000));
								$body = str_replace($matches[1], "<$hash>" . $matches[3] . "</$hash>", $body);
								$body = strip_tags($body, "<$hash>");
								$start = strpos($body, "<$hash>" . $matches[3] . "</$hash>");
								$length = strlen("<$hash>" . $matches[3] . "</$hash>");
								$snippet = str_replace(
									array(
										"<$hash>",
										"</$hash>",
									),
									array(
										'',
										'',
									),
									trim(substr($body, $start - 100, $length + 200))
								);
								$this->set('snippet', $snippet);
							}
							else
							{
								$this->error('could_not_parse_link_href_from_link');
								return false;
							}
						}

						return true;
					}
					else
					{
						$this->error('failed_to_parse_html_body');
						return false;
					}
				}
				else
				{
					$this->error('failed_to_retrieve_body_' . $url);
					return false;
				}
			}

			if ($this->fetch_field('state') == 'visible' AND !$this->info['skip_akismet'])
			{
				$akismet_url = $this->registry->options['bburl'] . '/blog.php';
				$permalink = $this->registry->options['bburl'] . '/blog.php?b= ' . $this->fetch_field('blogid');
				if (!empty($this->registry->options['vb_antispam_key']))
				{ // global key, use the global URL aka blog.php
					$akismet_key = $this->registry->options['vb_antispam_key'];
				}
				else
				{
					$akismet_key = $this->info['akismet_key'];
					$akismet_url = $this->registry->options['bburl'] . '/blog.php?u=' . $this->fetch_field('userid');
				}

				if (!empty($akismet_key))
				{
					// these are taken from the Akismet API: http://akismet.com/development/api/
					$akismet_data = array();
					$akismet_data['user_ip'] = IPADDRESS;
					$akismet_data['user_agent'] = USER_AGENT;
					$akismet_data['permalink'] = $permalink;
					$akismet_data['comment_type'] = 'trackback';
					$akismet_data['comment_author_url'] = $this->fetch_field('url');
					$akismet_data['comment_content'] = $this->fetch_field('snippet');
					if (verify_akismet_status($akismet_key, $akismet_url, $akismet_data) == 'spam')
					{
						$this->set('state', 'moderation');
					}
				}
			}

		}

		$return_value = true;
		($hook = vBulletinHook::fetch_hook('blog_trackbackdata_presave')) ? eval($hook) : false;

		$this->presave_called = $return_value;
		return $return_value;
	}
Exemple #4
0
	/**
	* Handles a [video] tag. Displays a movie.
	*
	* @param	string	The code to display
	*
	* @return	string	HTML representation of the tag.
	*/
	function handle_bbcode_video($url, $option)
	{
		global $vbulletin, $vbphrase, $show;

		static $providers = array();
		static $scraped = 0;

		$search = $replace = array();
		($hook = vBulletinHook::fetch_hook('data_preparse_bbcode_video_start')) ? eval($hook) : false;

		if (!$providers)
		{
			$bbcodes = $vbulletin->db->query_read_slave("
				SELECT
					provider, url, regex_url, regex_scrape, tagoption
				FROM " . TABLE_PREFIX . "bbcode_video
				ORDER BY priority
			");
			while ($bbcode = $vbulletin->db->fetch_array($bbcodes))
			{
				$providers["$bbcode[tagoption]"] = $bbcode;
			}
		}

		if (!empty($providers))
		{
			$match = false;
			foreach ($providers AS $provider)
			{
				$addcaret = ($provider['regex_url'][0] != '^') ? '^' : '';
				if (preg_match('#' . $addcaret . $provider['regex_url'] . '#si', $url, $match))
				{
					break;
				}
			}
			if ($match)
			{
				if (!$provider['regex_scrape'] AND $match[1])
				{
					return '[video=' . $provider['tagoption'] . ';' . $match[1] . ']' . $url . '[/video]';
				}
				else if ($provider['regex_scrape'] AND $vbulletin->options['bbcode_video_scrape'] > 0 AND $scraped < $vbulletin->options['bbcode_video_scrape'])
				{
					require_once(DIR . '/includes/functions_file.php');
					$result = fetch_body_request($url);
					if (preg_match('#' . $provider['regex_scrape'] . '#si', $result, $scrapematch))
					{
						return '[video=' . $provider['tagoption'] . ';' . $scrapematch[1] . ']' . $url . '[/video]';
					}
					$scraped++;
				}
			}
		}

		return '[video]' . $url . '[/video]';
	}
/**
* Send a pingback / trackback request
*
* @param	array	Bloginfo
* @param	string	Destination URL
* @param	string	Title of the blog
*
* @return	mixed	error string on failure, true on success or apparent success
*/
function send_ping_notification(&$bloginfo, $desturl, $blogtitle)
{
	global $vbulletin;

	if (!intval($bloginfo['blogid']))
	{
		return false;
	}

	$ourblogurl = $vbulletin->options['bburl'] . '/blog.php?blogid=' . $bloginfo['blogid'];
	$pingback_dest = '';
	$trackback_dest = $desturl;

	require_once(DIR . '/includes/functions_file.php');
	if ($headresult = fetch_head_request($desturl))
	{
		if (!empty($headresult['x-pingback']))
		{
			$pingback_dest = $headresult['x-pingback'];
		}
		else if ($headresult['http-response']['statuscode'] == 200 AND preg_match('#text\/html#si', $headresult['content-type']))
		{
			// Limit to 5KB
			// Consider adding the ability to Kill the transfer on </head>\s+*<body to class_vurl.php
			if ($bodyresult = fetch_body_request($desturl, 5120))
			{
				// search head for <link rel="pingback" href="pingback server">
				if (preg_match('<link rel="pingback" href="([^"]+)" ?/?>', $bodyresult, $matches))
				{
					$pingback_dest = $matches[0];
				}
				else	if (preg_match('#<rdf:Description((?!<\/rdf:RDF>).)*dc:identifier="' . preg_quote($desturl, '#') . '".*<\/rdf:RDF>#siU', $bodyresult))
				{
					if (preg_match('#<rdf:Description(?:(?!<\/rdf:RDF>).)*trackback:ping="([^"]+)".*<\/rdf:RDF>#siU', $bodyresult, $matches))
					{
						$trackback_dest = trim($matches[1]);
					}
				}
			}
		}

		if (!empty($pingback_dest))
		{
			// Client
			require_once(DIR . '/includes/class_xmlrpc.php');
			$xmlrpc = new vB_XMLRPC_Client($vbulletin);
			$xmlrpc->build_xml_call('pingback.ping', $ourblogurl, $desturl);
			if ($pingresult = $xmlrpc->send_xml_call($pingback_dest))
			{
				require_once(DIR . '/includes/class_xmlrpc.php');
				$xmlrpc_server = new vB_XMLRPC_Server($vbulletin);
				$xmlrpc_server->parse_xml($pingresult['body']);
				$xmlrpc_server->parse_xmlrpc();
			}

			// NOT FINSIHED
			write_trackback_log('pingback', 'out', 0, $pingresult, $bloginfo, $desturl);
			// Not always a success but we can't know for sure
			return true;
		}
		else
		{
			// Client
			require_once(DIR . '/includes/class_trackback.php');
			$tb = new vB_Trackback_Client($vbulletin);
			$excerpt = fetch_censored_text(fetch_trimmed_title(strip_bbcode(strip_quotes($bloginfo['pagetext']), false, true), 255));
			if ($result = $tb->send_ping($trackback_dest, $ourblogurl, $bloginfo['title'], $excerpt, $blogtitle))
			{
				require_once(DIR . '/includes/class_xml.php');
				$xml_object = new vB_XML_Parser($result['body']);
				$xml_object->include_first_tag = true;
				if ($xml_object->parse_xml() AND $xml_object->parseddata['response']['error'] === '0')
				{
					write_trackback_log('trackback', 'out', 0, $result, $bloginfo, $desturl);
					return true;
				}
			}

			write_trackback_log('trackback', 'out', 3, $result, $bloginfo, $desturl);
			// Not always a success but we can't know for sure
			return true;
		}
	}

	write_trackback_log('none', 'out', 1, '', $bloginfo, $desturl);

	return false;
}