本文整理汇总了PHP中Gadget类的典型用法代码示例。如果您正苦于以下问题:PHP Gadget类的具体用法?PHP Gadget怎么用?PHP Gadget使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gadget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createRewriteFeature
public function createRewriteFeature(Gadget $gadget)
{
$requires = $gadget->getRequires();
if (!isset($requires[ContentRewriteFeature::$REWRITE_TAG])) {
return;
}
$rewriteFeature = $requires[ContentRewriteFeature::$REWRITE_TAG];
$rewriteParams = $rewriteFeature->getParams();
if (isset($rewriteParams[ContentRewriteFeature::$INCLUDE_URLS])) {
$this->includeParam = $this->normalizeParam($rewriteParams[ContentRewriteFeature::$INCLUDE_URLS], '//');
} else {
$this->includeParam = '//';
}
if (isset($rewriteParams[ContentRewriteFeature::$EXCLUDE_URLS])) {
$this->excludeParam = $this->normalizeParam($rewriteParams[ContentRewriteFeature::$EXCLUDE_URLS], '//');
} else {
$this->excludeParam = '//';
}
if (isset($rewriteParams[ContentRewriteFeature::$INCLUDE_TAGS])) {
$this->tagsParam = $rewriteParams[ContentRewriteFeature::$INCLUDE_TAGS];
$this->tagsParam = explode(',', $this->tagsParam);
} else {
$this->tagsParam = array();
}
if ($this->excludeParam == '.*' || $this->includeParam == null) {
$this->includeNone = true;
}
if ($this->includeParam == '.*' || $this->excludeParam == null) {
$this->includeAll = true;
}
}
示例2: rewriteGadgetView
public function rewriteGadgetView(Gadget $gadget, ViewSpec $gadgetView)
{
// Dont rewrite content if the spec is unavailable
$requires = $gadget->getRequires();
if (isset($requires[ContentRewriteFeature::$REWRITE_TAG])) {
// Store the feature in the spec so we dont keep parsing it
$rewriteFeature = new ContentRewriteFeature();
$rewriteFeature->createRewriteFeature($gadget);
} else {
return false;
}
if (!$rewriteFeature->isRewriteEnabled()) {
return false;
}
if (ContentRewriteFeature::$PROXY_URL != null) {
$defaultTags = ContentRewriteFeature::defaultHTMLTags();
$htmlTags = null;
if (count($rewriteFeature->getTagsParam()) > 0) {
foreach ($rewriteFeature->getTagsParam() as $tag) {
if (isset($defaultTags[$tag])) {
$htmlTags[$tag] = $defaultTags[$tag];
}
}
} else {
$htmlTags = $defaultTags;
}
}
$gadgetView->setRewrittenContent($this->rewrite($gadgetView->getContent(), $htmlTags, $rewriteFeature->getExcludeParam(), $rewriteFeature->getIncludeParam(), Config::get('web_prefix') . ContentRewriteFeature::$PROXY_URL, $gadget->getId()->getURI(), $rewriteFeature->getTagsParam()));
return true;
}
示例3: up
public function up()
{
$gadget = new Gadget();
$gadget->setType('loginTop');
$gadget->setName('loginForm');
$gadget->setSortOrder(10);
$gadget->save();
}
示例4: setUp
/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
parent::setUp();
$this->gadgetContext = new GadgetContext('GADGET');
$gadgetSpecFactory = new MockRewriterGadgetFactory($this->gadgetContext, null);
$gadgetSpecFactory->fetchGadget = null;
$this->gadget = $gadgetSpecFactory->createGadget();
$this->gadgetRewriter = new GadgetRewriter($this->gadgetContext);
$this->view = $this->gadget->getView($this->gadgetContext->getView());
}
示例5: getIframeURL
private function getIframeURL(Gadget $gadget, GadgetContext $context)
{
$v = $gadget->getChecksum();
$view = $gadget->getView($context->getView());
$up = '';
foreach ($gadget->gadgetSpec->userPrefs as $pref) {
$up .= '&up_' . urlencode($pref['name']) . '=' . urlencode($pref['value']);
}
$locale = $context->getLocale();
//Note: putting the URL last, else some browsers seem to get confused (reported by hi5)
return Config::get('default_iframe_prefix') . 'container=' . $context->getContainer() . ($context->getIgnoreCache() ? '&nocache=1' : '&v=' . $v) . ($context->getModuleId() != 0 ? '&mid=' . $context->getModuleId() : '') . '&lang=' . $locale['lang'] . '&country=' . $locale['country'] . '&view=' . $view['view'] . $up . '&url=' . urlencode($context->getUrl());
}
示例6: up
public function up()
{
$criteria = new Criteria();
$criteria->add(GadgetPeer::TYPE, 'mobileLoginContents');
$criteria->add(GadgetPeer::NAME, 'loginForm');
if (!GadgetPeer::doSelectOne($criteria)) {
$gadget = new Gadget();
$gadget->setType('mobileLoginContents');
$gadget->setName('loginForm');
$gadget->setSortOrder(10);
$gadget->save();
}
}
示例7: save
public function save()
{
foreach ($this->values as $type => $gadgets) {
if (!$gadgets) {
continue;
}
foreach ($gadgets as $value) {
$gadget = new Gadget();
$gadget->setType($type);
$gadget->setName($value);
$gadget->save();
}
}
}
示例8: renderGadget
/**
*
* @param Gadget $gadget
* @throws GadgetException
*/
protected function renderGadget(Gadget $gadget)
{
$view = $gadget->getView($this->context->getView());
$renderClasses = Config::get('gadget_renderer');
foreach ($renderClasses as $renderClass => $constraints) {
// if current view meets the configurated renderer constraints
// render the gadget and stop checking
if ($this->checkConstraints($view, $constraints)) {
$gadgetRenderer = new $renderClass($this->context);
$gadgetRenderer->renderGadget($gadget, $view);
return;
}
}
throw new GadgetException("Invalid view type");
}
示例9: getList
private function getList()
{
$data = array();
$result = $this->getResult();
$gadgets = Gadget::loadStructuredList();
foreach ($gadgets as $category => $list) {
if (!$this->neededNames || isset($this->neededNames[$category])) {
$row = array();
if (isset($this->props['name'])) {
$row['name'] = $category;
}
if ($category !== "") {
if (isset($this->props['title'])) {
$row['desc'] = wfMessage("gadget-section-{$category}")->parse();
}
}
if (isset($this->props['members'])) {
$row['members'] = count($list);
}
$data[] = $row;
}
}
$result->setIndexedTagName($data, 'category');
$result->addValue('query', $this->getModuleName(), $data);
}
示例10: log_user_in
/**
* logs a user in
*
* Status Codes:<br />
* 0: success<br />
* 1: incorrect password<br />
* 1: incorrect email<br />
*
* @param String $u Username
* @param String $p Password
* @param Boolean $redirect redirect on successful login
* @return Int status code
*/
public static function log_user_in($u, $p, $redirect = true) {
if ($_SESSION['logged_in']) {
self::logout();
}
$u = dbi()->escape($u);
$ip = $_SESSION['IpAddr'];
if ($row = dbi()->q_1("SELECT CustomerID, Password FROM Customers WHERE Email = '$u'")) {
if (crypt($p, $row->Password) == $row->Password) { // match found
self::force_login($row->CustomerID);
if ($redirect) {
if ($_SESSION['last_page']) {
$page = $_SESSION['last_page'];
unset($_SESSION['last_page']);
} else {
$page = '/';
}
Gadget::redirect($page);
}
return 0;
} else { // incorrect password
return 1;
}
} else { // email not found
return 2;
}
}
示例11: testPreferences
function testPreferences()
{
global $wgUser, $wgOut, $wgTitle;
// This test makes call to the parser which requires valids Outputpage
// and Title objects. Set them up there, they will be released at the
// end of the test.
$old_wgOut = $wgOut;
$old_wgTitle = $wgTitle;
$wgTitle = Title::newFromText('Parser test for Gadgets extension');
// Proceed with test setup:
$prefs = array();
$context = new RequestContext();
$wgOut = $context->getOutput();
$wgOut->setTitle(Title::newFromText('test'));
Gadget::loadStructuredList('* foo | foo.js
==keep-section1==
* bar| bar.js
==remove-section==
* baz [rights=embezzle] |baz.js
==keep-section2==
* quux [rights=read] | quux.js');
$this->assertTrue(GadgetHooks::getPreferences($wgUser, $prefs), 'GetPrefences hook should return true');
$options = $prefs['gadgets']['options'];
$this->assertFalse(isset($options['<gadget-section-remove-section>']), 'Must not show empty sections');
$this->assertTrue(isset($options['<gadget-section-keep-section1>']));
$this->assertTrue(isset($options['<gadget-section-keep-section2>']));
// Restore globals
$wgOut = $old_wgOut;
$wgTitle = $old_wgTitle;
}
示例12: renderGadget
protected function renderGadget(Gadget $gadget)
{
$view = $gadget->getView($this->context->getView());
if ($view['type'] == 'URL') {
require_once "src/gadgets/render/GadgetUrlRenderer.php";
$gadgetRenderer = new GadgetUrlRenderer($this->context);
} elseif ($view['type'] == 'HTML' && empty($view['href'])) {
require_once "src/gadgets/render/GadgetHtmlRenderer.php";
$gadgetRenderer = new GadgetHtmlRenderer($this->context);
} elseif (empty($view['type']) || !empty($view['href'])) {
require_once "src/gadgets/render/GadgetHrefRenderer.php";
$gadgetRenderer = new GadgetHrefRenderer($this->context);
} else {
throw new GadgetException("Invalid view type");
}
$gadgetRenderer->renderGadget($gadget, $view);
}
示例13: __construct
public function __construct(Gadget $gadget, $options = array(), $CSRFSecret = null)
{
$this->gadget = $gadget;
parent::__construct(array(), $options, $CSRFSecret);
$config = Doctrine::getTable('Gadget')->getGadgetConfigListByType($options['type']);
if (empty($config[$gadget->getName()]['config'])) {
throw new RuntimeException('The gadget has not registered or it doesn\'t have any configuration items.');
}
$gadgetConfig = $config[$gadget->getName()]['config'];
foreach ($gadgetConfig as $key => $value) {
$this->setWidget($key, opFormItemGenerator::generateWidget($value));
$this->setValidator($key, opFormItemGenerator::generateValidator($value));
$config = Doctrine::getTable('GadgetConfig')->retrieveByGadgetIdAndName($gadget->getId(), $key);
if ($config) {
$this->setDefault($key, $config->getValue());
}
}
$this->widgetSchema->setNameFormat('gadget_config[%s]');
}
示例14: up
public function up()
{
$eventNavigation = new Navigation();
$eventNavigation->setType('community');
$eventNavigation->setUri('communityEvent/listCommunity');
$eventNavigation->setSortOrder(6);
$eventNavigation->setCaption('Events', 'en');
$eventNavigation->setCaption('イベントリスト', 'ja_JP');
$gadget = new Gadget();
$gadget->setType('contents');
$gadget->setName('recentCommunityEventComment');
$gadget->setSortOrder(132);
$gadget->save();
$gadget = new Gadget();
$gadget->setType('mobileContents');
$gadget->setName('recentCommunityEventComment');
$gadget->setSortOrder(111);
$gadget->save();
}
示例15: up
public function up()
{
$gadget = new Gadget();
$gadget->setType('top');
$gadget->setName('birthdayBox');
$gadget->setSortOrder(0);
$gadget->save();
$gadget = new Gadget();
$gadget->setType('mobileTop');
$gadget->setName('birthdayBox');
$gadget->setSortOrder(0);
$gadget->save();
$gadget = new Gadget();
$gadget->setType('profileTop');
$gadget->setName('birthdayBox');
$gadget->setSortOrder(0);
$gadget->save();
$gadget = new Gadget();
$gadget->setType('mobileProfileTop');
$gadget->setName('birthdayBox');
$gadget->setSortOrder(0);
$gadget->save();
}