Example #1
0
	/**
	 * Returns the config view for the widget.
	 *
	 * @return vBCms_View_Widget				- The view result
	 */
	public function getConfigView($widget = false)
	{
		global $vbulletin, $messagearea, $vbphrase;

		$this->assertWidget();

		require_once DIR . '/includes/functions_editor.php';
		require_once DIR . '/packages/vbcms/wysiwyghtmlparser.php';
		require_once DIR . '/packages/vbcms/editor/override.php';
		require_once DIR . '/packages/vbcms/bbcode/html.php';
		require_once DIR . '/packages/vbcms/bbcode/wysiwyg.php';
		require_once DIR . '/includes/functions_databuild.php';
		fetch_phrase_group('posting');

		vB::$vbulletin->input->clean_array_gpc('r', array(
			'do'      => vB_Input::TYPE_STR,
			'message' => vB_Input::TYPE_STR,
			'wysiwyg' => vB_Input::TYPE_BOOL,
			'template_name'    => vB_Input::TYPE_STR
		));

		$view = new vB_View_AJAXHTML('cms_widget_config');
		$view->title = new vB_Phrase('vbcms', 'configuring_widget_x', $this->widget->getTitle());

		$config = $this->widget->getConfig();

		if ((vB::$vbulletin->GPC['do'] == 'config') AND $this->verifyPostId())
		{
			if (vB::$vbulletin->GPC['wysiwyg'])
			{
				$html_parser = new vBCms_WysiwygHtmlParser(vB::$vbulletin);
				$message = $html_parser->parse(vB::$vbulletin->GPC['message']);
			}
			else
			{
				$message = convert_urlencoded_unicode(vB::$vbulletin->GPC['message']);
			}

			$widgetdm = new vBCms_DM_Widget($this->widget);
			if (vB::$vbulletin->GPC_exists['template_name'])
			{
				$config['template_name'] = vB::$vbulletin->GPC['template_name'];
			}

			$widgetdm->set('config', $config);

			if ($this->content)
			{
				$widgetdm->setConfigNode($this->content->getNodeId());
			}

			$widgetdm->save();

			if (!$widgetdm->hasErrors())
			{
				if ($this->content)
				{
					$segments = array('node' => $this->content->getNodeURLSegment(),
										'action' => vB_Router::getUserAction('vBCms_Controller_Content', 'EditPage'));
					$view->setUrl(vB_View_AJAXHTML::URL_FINISHED, vBCms_Route_Content::getURL($segments));
				}

				$view->setStatus(vB_View_AJAXHTML::STATUS_FINISHED, new vB_Phrase('vbcms', 'configuration_saved'));
			}
			else
			{
				if (vB::$vbulletin->debug)
				{
					$view->addErrors($widgetdm->getErrors());
				}

				// only send a message
				$view->setStatus(vB_View_AJAXHTML::STATUS_MESSAGE, new vB_Phrase('vbcms', 'configuration_failed'));
			}
		}
		else
		{
			// add the config content
			$configview = $this->createView('config');

			if (!isset($config['template_name']) OR ($config['template_name'] == '') )
			{
				$config['template_name'] = 'vbcms_widget_staticbb_page';
			}
			// add the config content
			$configview->template_name = $config['template_name'];

			//make the editor
			$configview->editorid = construct_edit_toolbar(
				$pagetext,
				false,
				new vBCms_Editor_Override(vB::$vbulletin),
				true,
				true,
				true,
				'cms_article',
				'',
				array()
			);

			$templater = vB_Template::create('vbcms_widgetcontent_editor');

			$templater->register('values', $values);
			$templater->register('widgetid', $this->widget->getId());

			$templater->register('disablesmiliesoption', true);
			$templater->register('editorid', $configview->editorid);
			$templater->register('messagearea', $messagearea);
			$configview->editor = $templater->render();
//			$configview->editor = $this->getConfigEditorView();
			// item id to ensure form is submitted to us
			$this->addPostId($configview);

			$view->setContent($configview);

			// send the view
			$view->setStatus(vB_View_AJAXHTML::STATUS_VIEW, new vB_Phrase('vbcms', 'configuring_widget'));
		}

		return $view;
	}
Example #2
0
	/**
	 * Returns the config view for the widget.
	 *
	 * @param	vB_Widget	$widget
	 * @return vBCms_View_Widget				- The view result
	 */
	public function getConfigView($widget = false)
	{
		$this->assertWidget();
		require_once DIR . '/includes/functions_databuild.php';
		fetch_phrase_group('cpcms');
		fetch_phrase_group('vbblock');
		fetch_phrase_group('vbblocksettings');

		vB::$vbulletin->input->clean_array_gpc('r', array(
			'do'     => vB_Input::TYPE_STR,
			'template_name' => vB_Input::TYPE_STR,
			'cache_ttl' => vB_Input::TYPE_INT,
			'commentusernames' => vB_Input::TYPE_STR,
			'postusernames' => vB_Input::TYPE_STR,
			'taglist' => vB_Input::TYPE_STR,
			'blogid' => vB_Input::TYPE_STR,
			'cat_case_sensitive' => vB_Input::TYPE_INT,
			'messagemaxchars' => vB_Input::TYPE_INT,
			'categories' => vB_Input::TYPE_STR,
			'days' => vB_Input::TYPE_INT,
			'count'    => vB_Input::TYPE_INT
		));


		$view = new vB_View_AJAXHTML('cms_widget_config');
		$view->title = new vB_Phrase('vbcms', 'configuring_widget_x', $this->widget->getTitle());

		$config = $this->widget->getConfig();

		if ((vB::$vbulletin->GPC['do'] == 'config') AND $this->verifyPostId())
		{

			$widgetdm = new vBCms_DM_Widget($this->widget);

			if (vB::$vbulletin->GPC_exists['template_name'])
			{
				$config['template_name'] = vB::$vbulletin->GPC['template_name'];
			}

			if (vB::$vbulletin->GPC_exists['days'])
			{
				$config['days'] = vB::$vbulletin->GPC['days'];
			}

			if (vB::$vbulletin->GPC_exists['count'])
			{
				$config['count'] = vB::$vbulletin->GPC['count'];
			}

			if (vB::$vbulletin->GPC_exists['cache_ttl'])
			{
				$config['cache_ttl'] = vB::$vbulletin->GPC['cache_ttl'];
			}

			if (vB::$vbulletin->GPC_exists['messagemaxchars'])
			{
				$config['messagemaxchars'] = vB::$vbulletin->GPC['messagemaxchars'];
			}

			if (vB::$vbulletin->GPC_exists['commentusernames'])
			{
				//We could be passed an empty string. If so, clear the existing value
				if (empty(vB::$vbulletin->GPC['commentusernames']))
				{
					$config['commentuserid'] = '';
				}
				else
				{
					//We are passed names. We need to turn those into user id's
					$usernames = explode(',', vB::$vbulletin->GPC['commentusernames']);

					foreach ($usernames as $key => $username)
					{
						$usernames[$key] = "'" . vB::$db->escape_string(trim($username)) . "'";
					}
					$sql = "SELECT username, userid FROM " . TABLE_PREFIX . "user
					WHERE username IN (" . implode(',', $usernames) . ") ORDER BY lower(username)";

					if ($rst = vB::$db->query_read($sql))
					{
						$userids = array();
						while($record = vB::$db->fetch_array($rst))
						{
							$userids[$record['userid']] = $record['username'];
						}
					}
					$config['commentuserid'] = $userids;
				}
			}

			if (vB::$vbulletin->GPC_exists['postusernames'])
			{
				//We could be passed an empty string. If so, clear the existing value
				if (empty(vB::$vbulletin->GPC['postusernames']))
				{
					$config['postuserid'] = '';
				}
				else
				{
					//We are passed names. We need to turn those into user id's
					$usernames = explode(',', vB::$vbulletin->GPC['postusernames']);

					foreach ($usernames as $key => $username)
					{
						$usernames[$key] = "'" . vB::$db->escape_string(trim($username)) . "'";
					}
					$sql = "SELECT username, userid FROM " . TABLE_PREFIX . "user
					WHERE username IN (" . implode(',', $usernames) . ") ORDER BY lower(username)";

					if ($rst = vB::$db->query_read($sql))
					{
						$userids = array();
						while($record = vB::$db->fetch_array($rst))
						{
							$userids[$record['userid']] = $record['username'];
						}
					}
					$config['postuserid'] = $userids;
				}
			}

			if (vB::$vbulletin->GPC_exists['taglist'])
			{
				//We could be passed an empty string. If so, clear the existing value
				if (empty(vB::$vbulletin->GPC['taglist']))
				{
					$config['taglist'] = '';
				}
				else
				{
					//We need to confirm these are valid tags
					$tags = explode(',', vB::$vbulletin->GPC['taglist']);

					foreach ($tags as $key => $tag)
					{
						$tags[$key] = "'" . vB::$db->escape_string(trim($tag)) . "'";
					}
					$sql = "SELECT tagid, tagtext FROM " . TABLE_PREFIX . "tag
					WHERE tagtext IN (" . implode(',', $tags) . ")
					ORDER BY tagtext";

					if ($rst = vB::$db->query_read($sql))
					{
						$tagids = array();
						while($record = vB::$db->fetch_array($rst))
						{
							$tagids[$record['tagid']] = $record['tagtext'];
						}
					}
					$config['taglist'] = $tagids;
				}
			}


			if (vB::$vbulletin->GPC_exists['blogid'])
			{
				//We could be passed an empty string. If so, clear the existing value
				if (empty(vB::$vbulletin->GPC['blogid']))
				{
					$config['blogid'] = '';
				}
				else
				{
					//We need to confirm these are valid ids
					$blogids = explode(',', vB::$vbulletin->GPC['blogid']);
					$blogid_checked = array();

					foreach ($blogids as $key => $blogid)
					{
						if (intval(intval($blogid)))
						{

						}
						$blogid_checked[] = intval($blogid);
					}

					$sql = "SELECT blogid FROM " . TABLE_PREFIX . "blog
					WHERE blogid IN (" . implode(',', $blogid_checked) . ")";

					if ($rst = vB::$db->query_read($sql))
					{
						$blogids = array();
						while($record = vB::$db->fetch_array($rst))
						{
							$blogids[] = $record['blogid'];
						}
					}
					$config['blogid'] = implode(',', $blogids);
				}
			}
			if (vB::$vbulletin->GPC_exists['categories'])
			{
				//We could be passed an empty string. If so, clear the existing value
				if (vB::$vbulletin->GPC['categories'] == '')
				{
					$config['categories'] = '';
				}
				else
				{
					$categories = explode(',', vB::$vbulletin->GPC['categories']);

					foreach ($categories as $key => $category)
					{
						$categories[$key] = "'" . vB::$db->escape_string(trim($category)) . "'";
					}

					$sql = "SELECT title, blogcategoryid FROM " . TABLE_PREFIX . "blog_category
					WHERE title IN (" . implode(',', $categories) . ")";

					if ($rst = vB::$db->query_read($sql))
					{
						$categories = array();
						while($record = vB::$db->fetch_array($rst))
						{
							$categories[$record['blogcategoryid']] = $record['title'];
						}
					}
					$config['categories'] = $categories;
				}
			}

			$widgetdm->set('config', $config);

			$widgetdm->save();

			if (!$widgetdm->hasErrors())
			{
				if ($this->content)
				{
					$segments = array('node' => $this->content->getNodeURLSegment(),
										'action' => vB_Router::getUserAction('vBCms_Controller_Content', 'EditPage'));
					$view->setUrl(vB_View_AJAXHTML::URL_FINISHED, vBCms_Route_Content::getURL($segments));
				}

				$view->setStatus(vB_View_AJAXHTML::STATUS_FINISHED, new vB_Phrase('vbcms', 'configuration_saved'));
			}
			else
			{
				if (vB::$vbulletin->debug)
				{
					$view->addErrors($widgetdm->getErrors());
				}

				// only send a message
				$view->setStatus(vB_View_AJAXHTML::STATUS_MESSAGE, new vB_Phrase('vbcms', 'configuration_failed'));
			}
		}
		else
		{
			// add the config content
			$configview = $this->createView('config');

			if (!isset($config['template_name']) OR ($config['template_name'] == '') )
			{
				$config['template_name'] = 'vbcms_widget_recentblog_page';
			}
			// add the config content
			$configview->template_name = $config['template_name'];
			$configview->days = $config['days'];
			$configview->count = $config['count'];
			$configview->messagemaxchars = $config['messagemaxchars'];
			$configview->blogid = $config['blogid'];

			if (!empty($config['postuserid']))
			{
				$configview->postusernames = implode(',', $config['postuserid']);
			}

			if (!empty($config['commentuserid']))
			{
				$configview->commentusernames = implode(',', $config['commentuserid']);
			}

			if (!empty($config['taglist']))
			{
				$configview->taglist = implode(',', $config['taglist']);
			}

			//Case sensitivity is an interesting issue. We will do the
			// search based on the db collation, which defaults to case
			// insensitive. But let's display in the stored value case
			$categories = array();

			if (!empty($config['categories']))
			{
				$lcase_categories = array();
				foreach($config['categories'] as $category)
				{
					if (!in_array(strtolower($category), $lcase_categories))
					{
						$categories[] = $category;
						$lcase_categories[] = strtolower($category);
					}
				}
				$configview->categories = implode(',', $config['categories']);
			}
			$configview->categories = implode(',', $categories);
			$configview->cache_ttl = $config['cache_ttl'];

			$this->addPostId($configview);

			$view->setContent($configview);

			// send the view
			$view->setStatus(vB_View_AJAXHTML::STATUS_VIEW, new vB_Phrase('vbcms', 'configuring_widget'));
		}

		return $view;
	}
Example #3
0
	print_input_row($vbphrase['title'], 'title');
	//print_input_row($vbphrase['varname'], 'varname', $widgetinfo['varname'], false);
	print_textarea_row($vbphrase['description'], 'description');
	print_submit_row($vbphrase['save'], '');
}

// New #########################################################################
if ($_REQUEST['do'] == 'newwidget')
{
	$vbulletin->input->clean_array_gpc('p', array(
		'widgettype'	=> TYPE_UINT,
		'title'    		=> TYPE_NOHTML,
		'description'   => TYPE_NOHTML
	));

	$widgetdm = new vBCms_DM_Widget();
	$widgetdm->set('widgettypeid', $vbulletin->GPC['widgettype']);
	$widgetdm->set('title', $vbulletin->GPC['title']);
	$widgetdm->set('description', $vbulletin->GPC['description']);
	//$widgetdm->set('varname', $vbulletin->GPC['varname']);

	if (!$widgetdm->save())
	{
		$errmsg = implode("\n<br /><br />", $widgetdm->getErrors());

		print_cp_message($errmsg);
	}

	define('CP_REDIRECT', 'cms_admin.php?do=widget');
	print_stop_message('saved_widget_successfully');
}
Example #4
0
	/**
	 * Returns the config view for the widget.
	 *
	 * @return vBCms_View_Widget				- The view result
	 */
	public function getConfigView($widget = false)
	{
		require_once DIR . '/includes/functions_databuild.php';
		fetch_phrase_group('cpcms');
		fetch_phrase_group('search');

		$this->assertWidget();

		vB::$vbulletin->input->clean_array_gpc('r', array(
			'do'      => vB_Input::TYPE_STR,
			'forumchoice' => vB_Input::TYPE_ARRAY,
			'template_name' => vB_Input::TYPE_STR,
			'cache_ttl' => vB_Input::TYPE_INT,
			'days' => vB_Input::TYPE_INT,
			'allow_html' => vB_Input::TYPE_INT,
			'count'    => vB_Input::TYPE_INT
		));

		$view = new vB_View_AJAXHTML('cms_widget_config');
		$view->title = new vB_Phrase('vbcms', 'configuring_widget_x', $this->widget->getTitle());

		$config = $this->widget->getConfig();

		if ((vB::$vbulletin->GPC['do'] == 'config') AND $this->verifyPostId())
		{
			$widgetdm = new vBCms_DM_Widget($this->widget);

			if (vB::$vbulletin->GPC_exists['template_name'])
			{
				$config['template_name'] = vB::$vbulletin->GPC['template_name'];
			}

			//make sure we have actual values for forumchoice
			if (vB::$vbulletin->GPC_exists['forumchoice'])
			{
				$config['forumchoice'] = vB::$vbulletin->GPC['forumchoice'];
			}

			if (vB::$vbulletin->GPC_exists['count'])
			{
				$config['count'] = vB::$vbulletin->GPC['count'];
			}

			if (vB::$vbulletin->GPC_exists['days'])
			{
				$config['days'] = vB::$vbulletin->GPC['days'];
			}

			if (vB::$vbulletin->GPC_exists['cache_ttl'])
			{
				$config['cache_ttl'] = vB::$vbulletin->GPC['cache_ttl'];
			}

			if (vB::$vbulletin->GPC_exists['template_name'])
			{
				$config['template_name'] = vB::$vbulletin->GPC['template_name'];
			}

			$config['allow_html'] = vB::$vbulletin->GPC_exists['allow_html'] ? 1 : 0;
			$widgetdm->set('config', $config);

			if ($this->content)
			{
				$widgetdm->setConfigNode($this->content->getNodeId());
			}

			$widgetdm->save();

			if (!$widgetdm->hasErrors())
			{
				if ($this->content)
				{
					$segments = array('node' => $this->content->getNodeURLSegment(),
										'action' => vB_Router::getUserAction('vBCms_Controller_Content', 'EditPage'));
					$view->setUrl(vB_View_AJAXHTML::URL_FINISHED, vBCms_Route_Content::getURL($segments));
				}

				$view->setStatus(vB_View_AJAXHTML::STATUS_FINISHED, new vB_Phrase('vbcms', 'configuration_saved'));
			}
			else
			{
				if (vB::$vbulletin->debug)
				{
					$view->addErrors($widgetdm->getErrors());
				}

				// only send a message
				$view->setStatus(vB_View_AJAXHTML::STATUS_MESSAGE, new vB_Phrase('vbcms', 'configuration_failed'));
			}
		}
		else
		{
			// add the config content
			$configview = $this->createView('config');

			if (!isset($config['template_name']) OR ($config['template_name'] == '') )
			{
				$config['template_name'] = 'vbcms_widget_staticbb_page';
			}
			// add the config content
			$configview->template_name = $config['template_name'];
			$configview->forumchoice_select = $this->getForums($config);
			$configview->days = $config['days'];
			$configview->count = $config['count'];
			$this->addPostId($configview);
			$configview->cache_ttl = $config['cache_ttl'];
			$configview->allow_html = $config['allow_html'];

			$view->setContent($configview);

			// send the view
			$view->setStatus(vB_View_AJAXHTML::STATUS_VIEW, new vB_Phrase('vbcms', 'configuring_widget'));
		}

		return $view;
	}