Allows access to theme controls from within views, to give themers a unified toolset for interacting with Vanilla from within views.
Since: 2.0
Author: Mark O'Sullivan (markm@vanillaforums.com)
/**
 * Takes a route and prepends the web root (expects "/controller/action/params" as $Path).
 *
 * @param array The parameters passed into the function.
 * The parameters that can be passed to this function are as follows.
 * - <b>path</b>: The relative path for the url. There are some special paths that can be used to return "intelligent" links:
 *    - <b>signinout</b>: This will return a signin/signout url that will toggle depending on whether or not the user is already signed in. When this path is given the text is automaticall set.
 * - <b>withdomain</b>: Whether or not to add the domain to the url.
 * - <b>text</b>: Html text to be put inside an anchor. If this value is set then an html <a></a> is returned rather than just a url.
 * - <b>id, class, etc.</b>: When an anchor is generated then any other attributes are passed through and will be written in the resulting tag.
 * @param Smarty The smarty object rendering the template.
 * @return The url.
 */
function smarty_function_link($Params, &$Smarty)
{
    $Path = GetValue('path', $Params, '', TRUE);
    $Text = GetValue('text', $Params, '', TRUE);
    $NoTag = GetValue('notag', $Params, FALSE, TRUE);
    $CustomFormat = GetValue('format', $Params, FALSE, TRUE);
    if (!$Text && $Path != 'signinout' && $Path != 'signin') {
        $NoTag = TRUE;
    }
    if ($CustomFormat) {
        $Format = $CustomFormat;
    } else {
        if ($NoTag) {
            $Format = '%url';
        } else {
            $Format = '<a href="%url" class="%class">%text</a>';
        }
    }
    $Options = array();
    if (isset($Params['withdomain'])) {
        $Options['WithDomain'] = $Params['withdomain'];
    }
    if (isset($Params['class'])) {
        $Options['class'] = $Params['class'];
    }
    if (isset($Params['tk'])) {
        $Options['TK'] = $Params['tk'];
    }
    if (isset($Params['target'])) {
        $Options['Target'] = $Params['target'];
    }
    $Result = Gdn_Theme::Link($Path, $Text, $Format, $Options);
    return $Result;
}
 /**
  * Runs before every call to this controller.
  */
 public function initialize()
 {
     parent::initialize();
     Gdn_Theme::section('Dashboard');
     set_time_limit(0);
     // Is this even doing anything?
 }
/**
 */
function smarty_function_signin_link($Params, &$Smarty)
{
    if (!Gdn::Session()->IsValid()) {
        $Wrap = GetValue('wrap', $Params, 'li');
        return Gdn_Theme::Link('signinout', GetValue('text', $Params, ''), GetValue('format', $Params, Wrap('<a href="%url" rel="nofollow" class="%class">%text</a>', $Wrap)), $Params);
    }
}
/**
 *
 *
 * @param array $Params
 * @param object $Smarty
 * @return string
 */
function smarty_function_nomobile_link($Params, &$Smarty)
{
    $Path = val('path', $Params, '', true);
    $Text = val('text', $Params, '', true);
    $Wrap = val('wrap', $Params, 'li');
    return Gdn_Theme::link('profile/nomobile', val('text', $Params, t("Full Site")), val('format', $Params, wrap('<a href="%url" class="%class">%text</a>', $Wrap)));
}
/**
 */
function smarty_function_category_link($Params, &$Smarty)
{
    $Path = GetValue('path', $Params, '', TRUE);
    $Text = GetValue('text', $Params, '', TRUE);
    $Wrap = GetValue('wrap', $Params, 'li');
    return Gdn_Theme::Link('category', GetValue('text', $Params, ''), GetValue('format', $Params, Wrap('<a href="%url" class="%class">%text</a>', $Wrap)));
}
/**
 * @copyright Copyright 2008, 2009 Vanilla Forums Inc.
 * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
 */
function smarty_function_module($Params, &$Smarty)
{
    $Name = GetValue('name', $Params);
    unset($Params['name']);
    $Result = Gdn_Theme::Module($Name, $Params);
    return $Result;
}
/**
 */
function smarty_function_nomobile_link($Params, &$Smarty)
{
    $Path = GetValue('path', $Params, '', TRUE);
    $Text = GetValue('text', $Params, '', TRUE);
    $Wrap = GetValue('wrap', $Params, 'li');
    return Gdn_Theme::Link('profile/nomobile', GetValue('text', $Params, T("Full Site")), GetValue('format', $Params, Wrap('<a href="%url" class="%class">%text</a>', $Wrap)));
}
/**
 *
 *
 * @param array $Params
 * @param object $Smarty
 * @return string
 */
function smarty_function_dashboard_link($Params, &$Smarty)
{
    $Path = val('path', $Params, '', true);
    $Text = val('text', $Params, '', true);
    $Wrap = val('wrap', $Params, 'li');
    return Gdn_Theme::link('dashboard', val('text', $Params, ''), val('format', $Params, wrap('<a href="%url" class="%class">%text</a>', $Wrap)));
}
/**
 * Render a breadcrumb trail for the user based on the page they are on.
 */
function smarty_function_breadcrumbs($Params, &$Smarty)
{
    $Breadcrumbs = $Smarty->Controller->Data('Breadcrumbs');
    if (is_array($Breadcrumbs)) {
        return Gdn_Theme::Breadcrumbs($Breadcrumbs);
    }
}
/**
 * A placeholder for future menu items.
 *
 * @param array $Params The parameters passed into the function.
 * @param Smarty $Smarty The smarty object rendering the template.
 * @return string
 */
function smarty_function_custom_menu($Params, &$Smarty)
{
    $Controller = $Smarty->Controller;
    if (is_object($Menu = val('Menu', $Controller))) {
        $Format = val('format', $Params, wrap('<a href="%url" class="%class">%text</a>', val('wrap', $Params, 'li')));
        $Result = '';
        foreach ($Menu->Items as $Group) {
            foreach ($Group as $Item) {
                // Make sure the item is a custom item.
                if (valr('Attributes.Standard', $Item)) {
                    continue;
                }
                // Make sure the user has permission for the item.
                if ($Permission = val('Permission', $Item)) {
                    if (!Gdn::session()->checkPermission($Permission)) {
                        continue;
                    }
                }
                if (($Url = val('Url', $Item)) && ($Text = val('Text', $Item))) {
                    $Attributes = val('Attributes', $Item);
                    $Result .= Gdn_Theme::link($Url, $Text, $Format, $Attributes) . "\r\n";
                }
            }
        }
        return $Result;
    }
    return '';
}
 /**
  * Runs before every call to this controller.
  */
 public function initialize()
 {
     parent::initialize();
     Gdn_Theme::section('Dashboard');
     $this->Model = new DBAModel();
     $this->Form = new Gdn_Form();
     $this->addJsFile('dba.js');
 }
 /**
  * Set menu path. Automatically run on every use.
  *
  * @since 2.0.0
  * @access public
  */
 public function initialize()
 {
     parent::initialize();
     Gdn_Theme::section('Dashboard');
     if ($this->Menu) {
         $this->Menu->highlightRoute('/dashboard/settings');
     }
 }
/**
 * Render a breadcrumb trail for the user based on the page they are on.
 */
function smarty_function_breadcrumbs($Params, &$Smarty)
{
    $Breadcrumbs = $Smarty->Controller->Data('Breadcrumbs');
    if (!is_array($Breadcrumbs)) {
        $Breadcrumbs = array();
    }
    return Gdn_Theme::Breadcrumbs($Breadcrumbs, GetValue('homelink', $Params, TRUE));
}
 public function PluginController_FileUpload_Create($Sender)
 {
     $Sender->Title('FileUpload');
     $Sender->AddSideMenu('plugin/fileupload');
     Gdn_Theme::Section('Dashboard');
     $Sender->Form = new Gdn_Form();
     $this->EnableSlicing($Sender);
     $this->Dispatch($Sender, $Sender->RequestArgs);
 }
 public function Initialize()
 {
     parent::Initialize();
     Gdn_Theme::Section('Dashboard');
     $this->Model = new DBAModel();
     $this->Form = new Gdn_Form();
     $this->Form->InputPrefix = '';
     $this->AddJsFile('dba.js');
 }
/**
 * Render a breadcrumb trail for the user based on the page they are on.
 *
 * @param array $Params
 * @param object $Smarty
 * @return string
 */
function smarty_function_breadcrumbs($Params, &$Smarty)
{
    $Breadcrumbs = $Smarty->Controller->data('Breadcrumbs');
    if (!is_array($Breadcrumbs)) {
        $Breadcrumbs = array();
    }
    $Options = arrayTranslate($Params, array('homeurl' => 'HomeUrl', 'hidelast' => 'HideLast'));
    return Gdn_Theme::breadcrumbs($Breadcrumbs, val('homelink', $Params, true), $Options);
}
 /**
  * Default search functionality.
  *
  * @since 2.0.0
  * @access public
  * @param int $Page Page number.
  */
 public function index($Page = '')
 {
     $this->addJsFile('search.js');
     $this->title(t('Search'));
     saveToConfig('Garden.Format.EmbedSize', '160x90', false);
     Gdn_Theme::section('SearchResults');
     list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20));
     $this->setData('_Limit', $Limit);
     $Search = $this->Form->getFormValue('Search');
     $Mode = $this->Form->getFormValue('Mode');
     if ($Mode) {
         $this->SearchModel->ForceSearchMode = $Mode;
     }
     try {
         $ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit);
     } catch (Gdn_UserException $Ex) {
         $this->Form->addError($Ex);
         $ResultSet = array();
     } catch (Exception $Ex) {
         LogException($Ex);
         $this->Form->addError($Ex);
         $ResultSet = array();
     }
     Gdn::userModel()->joinUsers($ResultSet, array('UserID'));
     // Fix up the summaries.
     $SearchTerms = explode(' ', Gdn_Format::text($Search));
     foreach ($ResultSet as &$Row) {
         $Row['Summary'] = SearchExcerpt(Gdn_Format::plainText($Row['Summary'], $Row['Format']), $SearchTerms);
         $Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']);
         $Row['Format'] = 'Html';
     }
     $this->setData('SearchResults', $ResultSet, true);
     $this->setData('SearchTerm', Gdn_Format::text($Search), true);
     if ($ResultSet) {
         $NumResults = count($ResultSet);
     } else {
         $NumResults = 0;
     }
     if ($NumResults == $Offset + $Limit) {
         $NumResults++;
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'More Results';
     $this->Pager->LessCode = 'Previous Results';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::url($Search));
     //		if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
     //         $this->setJson('LessRow', $this->Pager->toString('less'));
     //         $this->setJson('MoreRow', $this->Pager->toString('more'));
     //         $this->View = 'results';
     //      }
     $this->canonicalUrl(url('search', true));
     $this->render();
 }
/**
 * Takes a route and prepends the web root (expects "/controller/action/params" as $Path).
 *
 * @param array The parameters passed into the function.
 * The parameters that can be passed to this function are as follows.
 * - <b>path</b>: The relative path for the url. There are some special paths that can be used to return "intelligent" links:
 *    - <b>signinout</b>: This will return a signin/signout url that will toggle depending on whether or not the user is already signed in. When this path is given the text is automaticall set.
 * - <b>withdomain</b>: Whether or not to add the domain to the url.
 * - <b>text</b>: Html text to be put inside an anchor. If this value is set then an html <a></a> is returned rather than just a url.
 * - <b>id, class, etc.></b>: When an anchor is generated then any other attributes are passed through and will be written in the resulting tag.
 * @param Smarty The smarty object rendering the template.
 * @return The url.
 */
function smarty_function_forum_root_link($Params, &$Smarty)
{
    $Text = GetValue('text', $Params, '', TRUE);
    $Format = GetValue('format', $Params, '<li><a href="%url" class="%class">%text</a></li>');
    $Options = array();
    if (isset($Params['class'])) {
        $Options['class'] = $Params['class'];
    }
    $Result = Gdn_Theme::Link('forumroot', $Text, $Format, $Options);
    return $Result;
}
 /**
  * Make this look like a dashboard page and add the resources
  *
  * @since 1.0
  * @access public
  */
 public function Initialize()
 {
     parent::Initialize();
     $this->Application = 'Yaga';
     Gdn_Theme::Section('Dashboard');
     if ($this->Menu) {
         $this->Menu->HighlightRoute('/rank');
     }
     $this->AddJsFile('jquery-ui-1.10.0.custom.min.js');
     $this->AddJsFile('admin.ranks.js');
 }
 /**
  * Make this look like a dashboard page and add the resources
  *
  * @since 1.0
  * @access public
  */
 public function Initialize()
 {
     parent::Initialize();
     $this->Application = 'Yaga';
     Gdn_Theme::Section('Dashboard');
     if ($this->Menu) {
         $this->Menu->HighlightRoute('/badge');
     }
     $this->AddJsFile('admin.badges.js');
     $this->AddCssFile('badges.css');
 }
 /**
  * Make this look like a dashboard page and add the resources
  *
  * @since 1.0
  * @access public
  */
 public function Initialize()
 {
     parent::Initialize();
     $this->Application = 'Yaga';
     Gdn_Theme::Section('Dashboard');
     if ($this->Menu) {
         $this->Menu->HighlightRoute('/yaga');
     }
     $this->AddSideMenu('yaga/settings');
     $this->AddCssFile('yaga.css');
 }
 /**
  * Include JS and CSS used by all methods.
  *
  * Always called by dispatcher before controller's requested method.
  *
  * @since 2.0.0
  * @access public
  */
 public function initialize()
 {
     $this->Head = new HeadModule($this);
     $this->Head->addTag('meta', array('name' => 'robots', 'content' => 'noindex'));
     $this->addJsFile('jquery.js');
     $this->addJsFile('jquery.form.js');
     $this->addJsFile('jquery.popup.js');
     $this->addJsFile('jquery.gardenhandleajaxform.js');
     $this->addJsFile('global.js');
     $this->addCssFile('style.css');
     $this->addCssFile('vanillicon.css', 'static');
     parent::initialize();
     Gdn_Theme::section('Entry');
 }
 /**
  * Include JS, CSS, and modules used by all methods.
  *
  * Always called by dispatcher before controller's requested method.
  * 
  * @since 2.0.0
  * @access public
  */
 public function Initialize()
 {
     $this->Head = new HeadModule($this);
     $this->AddJsFile('jquery.js');
     $this->AddJsFile('jquery.livequery.js');
     $this->AddJsFile('jquery.form.js');
     $this->AddJsFile('jquery.popup.js');
     $this->AddJsFile('jquery.gardenhandleajaxform.js');
     $this->AddJsFile('global.js');
     $this->AddCssFile('style.css');
     // Add Modules
     $this->AddModule('GuestModule');
     $this->AddModule('SignedInModule');
     parent::Initialize();
     Gdn_Theme::Section('ActivityList');
     $this->SetData('Breadcrumbs', array(array('Name' => T('Activity'), 'Url' => '/activity')));
 }
 /**
  * Adds JS, CSS, & modules. Automatically run on every use.
  *
  * @since 2.0.0
  * @access public
  */
 public function Initialize()
 {
     $this->ModuleSortContainer = 'Profile';
     $this->Head = new HeadModule($this);
     $this->AddJsFile('jquery.js');
     $this->AddJsFile('jquery.livequery.js');
     $this->AddJsFile('jquery.form.js');
     $this->AddJsFile('jquery.popup.js');
     $this->AddJsFile('jquery.gardenhandleajaxform.js');
     $this->AddJsFile('global.js');
     $this->AddCssFile('style.css');
     $this->AddModule('GuestModule');
     parent::Initialize();
     Gdn_Theme::Section('Profile');
     if ($this->EditMode) {
         $this->CssClass .= 'EditMode';
     }
     $this->SetData('Breadcrumbs', array());
 }
 /**
  * Highlight route and do authenticator setup.
  *
  * Always called by dispatcher before controller's requested method.
  *
  * @since 2.0.3
  * @access public
  */
 public function initialize()
 {
     parent::initialize();
     Gdn_Theme::section('Dashboard');
     if ($this->Menu) {
         $this->Menu->highlightRoute('/dashboard/authentication');
     }
     $this->enableSlicing($this);
     $Authenticators = Gdn::authenticator()->GetAvailable();
     $this->ChooserList = array();
     $this->ConfigureList = array();
     foreach ($Authenticators as $AuthAlias => $AuthConfig) {
         $this->ChooserList[$AuthAlias] = $AuthConfig['Name'];
         $Authenticator = Gdn::authenticator()->authenticateWith($AuthAlias);
         $ConfigURL = is_a($Authenticator, "Gdn_Authenticator") && method_exists($Authenticator, 'AuthenticatorConfiguration') ? $Authenticator->AuthenticatorConfiguration($this) : false;
         $this->ConfigureList[$AuthAlias] = $ConfigURL;
     }
     $this->CurrentAuthenticationAlias = Gdn::authenticator()->authenticateWith('default')->getAuthenticationSchemeAlias();
 }
 /**
  * Settings screen placeholder
  *
  * @param mixed $Sender
  */
 public function Controller_Index($Sender)
 {
     Gdn_Theme::section('Moderation');
     $Sender->Permission('Garden.Settings.Manage');
     $Sender->Title('Community Reporting');
     $Sender->AddCssFile('reporting.css', 'plugins/Reporting');
     // Check to see if the admin is toggling a feature
     $Feature = GetValue('1', $Sender->RequestArgs);
     $Command = GetValue('2', $Sender->RequestArgs);
     $TransientKey = Gdn::request()->get('TransientKey');
     if (Gdn::Session()->ValidateTransientKey($TransientKey)) {
         if (in_array($Feature, array('awesome', 'report'))) {
             SaveToConfig('Plugins.Reporting.' . ucfirst($Feature) . 'Enabled', $Command == 'disable' ? FALSE : TRUE);
             Redirect('plugin/reporting');
         }
     }
     $CategoryModel = new CategoryModel();
     $Sender->SetData('Plugins.Reporting.Data', array('ReportEnabled' => $this->ReportEnabled, 'AwesomeEnabled' => $this->AwesomeEnabled));
     $Sender->Render($this->GetView('settings.php'));
 }
 /**
  * Default all drafts view: chronological by time saved.
  * 
  * @since 2.0.0
  * @access public
  * 
  * @param int $Offset Number of drafts to skip.
  */
 public function Index($Offset = '0')
 {
     Gdn_Theme::Section('DiscussionList');
     // Setup head
     $this->Permission('Garden.SignIn.Allow');
     $this->AddCssFile('vanilla.css');
     $this->AddJsFile('jquery.gardenmorepager.js');
     $this->AddJsFile('discussions.js');
     $this->Title(T('My Drafts'));
     // Validate $Offset
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     // Set criteria & get drafts data
     $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30);
     $Session = Gdn::Session();
     $Wheres = array('d.InsertUserID' => $Session->UserID);
     $this->DraftData = $this->DraftModel->Get($Session->UserID, $Offset, $Limit);
     $CountDrafts = $this->DraftModel->GetCount($Session->UserID);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'More drafts';
     $this->Pager->LessCode = 'Newer drafts';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, $CountDrafts, 'drafts/%1$s');
     // Deliver JSON data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'drafts';
     }
     // Add modules
     $this->AddModule('DiscussionFilterModule');
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $this->AddModule('BookmarkedModule');
     // Render default view (drafts/index.php)
     $this->Render();
 }
Exemple #28
0
/**
 * Writes the site logo to the page.
 *
 * @param array $Params The parameters passed into the function.
 * @param Smarty $Smarty The smarty object rendering the template.
 * @return The HTML img tag or site title if no logo is set.
 */
function smarty_function_logo($Params, &$Smarty)
{
    $Options = array();
    // Whitelist params to be passed on.
    if (isset($Params['alt'])) {
        $Options['alt'] = $Params['alt'];
    }
    if (isset($Params['class'])) {
        $Options['class'] = $Params['class'];
    }
    if (isset($Params['title'])) {
        $Options['title'] = $Params['title'];
    }
    if (isset($Params['height'])) {
        $Options['height'] = $Params['height'];
    }
    if (isset($Params['width'])) {
        $Options['width'] = $Params['width'];
    }
    $Result = Gdn_Theme::logo($Options);
    return $Result;
}
 public function Translate($Code, $Default = FALSE)
 {
     $Result = parent::Translate($Code, $Default);
     if (!$Code || substr($Code, 0, 1) == '@') {
         return $Result;
     }
     $Prefix = self::GuessPrefix();
     if (!$Prefix) {
         return $Result;
     }
     if ($Prefix == 'unknown') {
         decho($Code);
         decho(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
         die;
     }
     if (Gdn_Theme::InSection('Dashboard')) {
         $Prefix = 'dash_' . $Prefix;
     } else {
         $Prefix = 'site_' . $Prefix;
     }
     $this->_CapturedDefinitions[$Prefix][$Code] = $Result;
     return $Result;
 }
 /**
  * Default search functionality.
  *
  * @since 2.0.0
  * @access public
  * @param int $Page Page number.
  */
 public function index($Page = '')
 {
     $this->addJsFile('search.js');
     $this->title(t('Search'));
     saveToConfig('Garden.Format.EmbedSize', '160x90', false);
     Gdn_Theme::section('SearchResults');
     list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20));
     $this->setData('_Limit', $Limit);
     $Search = $this->Form->getFormValue('Search');
     $Mode = $this->Form->getFormValue('Mode');
     if ($Mode) {
         $this->SearchModel->ForceSearchMode = $Mode;
     }
     try {
         $ResultSet = $this->SearchModel->search($Search, $Offset, $Limit);
     } catch (Gdn_UserException $Ex) {
         $this->Form->addError($Ex);
         $ResultSet = array();
     } catch (Exception $Ex) {
         LogException($Ex);
         $this->Form->addError($Ex);
         $ResultSet = array();
     }
     Gdn::userModel()->joinUsers($ResultSet, array('UserID'));
     // Fix up the summaries.
     $SearchTerms = explode(' ', Gdn_Format::text($Search));
     foreach ($ResultSet as &$Row) {
         $Row['Summary'] = searchExcerpt(htmlspecialchars(Gdn_Format::plainText($Row['Summary'], $Row['Format'])), $SearchTerms);
         $Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']);
         $Row['Format'] = 'Html';
     }
     $this->setData('SearchResults', $ResultSet, true);
     $this->setData('SearchTerm', Gdn_Format::text($Search), true);
     $this->setData('_CurrentRecords', count($ResultSet));
     $this->canonicalUrl(url('search', true));
     $this->render();
 }