コード例 #1
0
 /**
  * The index action is the default action of this Wall Module. It prepares the widget
  * wall of the user and render the view according to its preferences.
  *
  * If the current user is not authenticated, it will be redirected to the users/index
  * action that will allows you to acces the login form of the application.
  *
  */
 public function index($continuePurchase = false, $langage = null, $forcebrowser = false)
 {
     # Try to force users to use firefox
     //		if(isset($_SESSION['forcebrowser']) && $_SESSION['forcebrowser'] == true){
     //			$forcebrowser = true;
     //		}
     //		if(!ereg("Firefox/",$_SERVER['HTTP_USER_AGENT']) && !$forcebrowser){
     //			require(DefaultFC::getView('compatibility.tpl'));
     //			die();
     //		}else{
     //			$_SESSION['forcebrowser'] = true;
     //		}
     if (Auth::isAuth()) {
         // Determine if the 'category widget' is installed.
         if (Widgets::isInstalled('categoryList')) {
             $widgetCategory = array('id' => 'categoryList', 'name' => 'Widget Categories');
         }
         // Determine if the 'tag cloud widget' is installed.
         if (Widgets::isInstalled('tagCloud')) {
             $widgetCloud = array('id' => 'tagCloud', 'name' => 'Widget Tag Cloud');
         }
         // Determine if the view must allow the user to manage widgets.
         $widgetManagement = false;
         if (Auth::isAdmin() || Auth::isGod()) {
             $widgetManagement = true;
         }
         // Determine if the view must show the list of installed widgets or
         // a link to the PALETTE Service Browser.
         $useServiceBrowser = USE_SERVICE_BROWSER;
         $serviceBrowserURI = USE_SERVICE_BROWSER ? SERVICE_BROWSER_URI . 'index.php/Services/Widgets?num=1' : null;
         require DefaultFC::getView('index.tpl');
     } else {
         DefaultFC::redirection('users/index?ref=wall');
     }
 }
コード例 #2
0
 /**
  * This function return the available langages according to the "locales" folder of
  * a installer widget.
  */
 public static function retrieveAvalaibleLanguage($widgetId)
 {
     $availableLanguage = array();
     # First get the code of languages
     if (Widgets::isInstalled($widgetId)) {
         # TODO verify that widgetId is the name of the locales folder of widget...
         $pathToWidget = dirname(__FILE__) . '/../widgets/' . $widgetId . '/locales/';
         if (is_dir($pathToWidget)) {
             if ($root = opendir($pathToWidget)) {
                 while (false !== ($file = readdir($root))) {
                     if (ereg('^[a-z\\-]+$', $file)) {
                         $availableLanguage[$file] = $file;
                     }
                 }
             }
         }
     }
     # Second, try to determine the language name
     if (isset($GLOBALS['l10n_catalogue'])) {
         // Come from /includes/l10n_catalogue.php
         reset($availableLanguage);
         $tmp = array();
         foreach ($availableLanguage as $code => $label) {
             # If the code exists in l10n catalogue get the name of the language
             if (isset($GLOBALS['l10n_catalogue'][$code])) {
                 $tmp[$code] = $GLOBALS['l10n_catalogue'][$code]['language'];
             } else {
                 $tmp[$code] = $label;
             }
         }
         $availableLanguage = $tmp;
     }
     asort($availableLanguage);
     return $availableLanguage;
 }
コード例 #3
0
 /**
  * Makes effective a subscribing to a given widget for a particular user in the database. If
  * the widget already exists in the user's UI, the call to this function will simply
  * be ignored.
  *
  * You have to know that if the widget is inserted in the user's UI, it will take place
  * in the first column of the screen, at the first place (in other words: top-left on the screen).
  *
  * @param integer $userId The user's identifier in the database
  * @param string $widgetId The widget's identifier to wich the user want to subscribe.
  */
 public static function subscribe($userId, $widgetId)
 {
     // Test if the widget exists. Developpers please be carefull, there's a dependancy on /models/Widgets::isInstalled.
     if (!Widgets::isInstalled($widgetId)) {
         throw new ServiceException(MwwException::MODEL, "Unable to subscribe user '{$userId}' to widget '{$widgetId}'. The widget is not installed.");
     }
     // Sanitization and database connexion.
     $db = DbUtil::accessFactory();
     $userId = $db->escape($userId);
     $widgetId = $db->escape($widgetId);
     // Test if the widget needs to be added to the user interface.
     # $rs = $db->select("SELECT * FROM interface as i, widget_instances as wi WHERE userid = ${userId} AND wi.instanceid = i.widgetinstanceid AND wi.widgetid = '${widgetId}'");
     # TODO Remove this ligne because in case of multi instanciation there is not this constrain
     //if($rs->isEmpty())
     //{
     // We can subscribe this user to the requested widget.
     // Developpers note : be careful the 'column' mysql keyword use in the following queries. Use brackets !
     # New instance
     $db->execute("INSERT INTO `widget_instances` (`widgetid`) VALUES ('" . $widgetId . "')");
     $widgetInstanceId = mysql_insert_id();
     # TODO test this, may be do a transaction and use clearbricks
     $db->execute("UPDATE interface SET position = position + 1 WHERE userid = {$userId} AND `column` = 0");
     $db->execute("INSERT INTO interface (userid, widgetinstanceid, `column`, minimized, position) VALUES ({$userId}, '{$widgetInstanceId}', '0', '0', '0')");
     //}
 }