Exemplo n.º 1
0
 public function init($args)
 {
     $args['ID'] = $this->id;
     $this->title = Kurogo::arrayVal($args, 'TITLE', $this->id);
     $this->description = Kurogo::arrayVal($args, 'DESCRIPTION');
     $this->rule = UserContextRule::factory($args);
 }
Exemplo n.º 2
0
 protected function parseEntry($entry)
 {
     switch ($this->response->getContext('retriever')) {
         case 'feed':
             $photo = new FlickrFeedPhotoObject();
             $photo->setID($entry['guid']);
             $photo->setAuthor($entry['author_name']);
             $photo->setMimeType($entry['photo_mime']);
             $photo->setURL($entry['photo_url']);
             $photo->setHeight($entry['height']);
             $photo->setWidth($entry['width']);
             $photo->setThumbnailURL($entry['thumb_url']);
             $published = new DateTime($entry['date_taken']);
             $photo->setPublished($published);
             $photo->setDescription($entry['description']);
             break;
         case 'api':
             $photo = new FlickrAPIPhotoObject();
             $photo->setUserID(Kurogo::arrayVal($entry, 'owner'));
             $photo->setID($entry['id']);
             $photo->setFarm($entry['farm']);
             $photo->setServer($entry['server']);
             $photo->setSecret($entry['secret']);
             $photo->setDescription($entry['description']['_content']);
             $photo->setAuthor($entry['ownername']);
             $published = new DateTime($entry['datetaken']);
             $photo->setPublished($published);
             $photo->setThumbnailURL($photo->getFlickrUrl('s'));
             $photo->setURL($photo->getFlickrUrl('z'));
             break;
     }
     $photo->setTitle($entry['title']);
     $photo->setTags($entry['tags']);
     return $photo;
 }
Exemplo n.º 3
0
 public function initializeForCommand()
 {
     switch ($this->command) {
         case 'notice':
             $response = null;
             $responseVersion = 1;
             if ($this->getOptionalModuleVar('BANNER_ALERT', false, 'notice')) {
                 $noticeData = $this->getOptionalModuleSection('notice');
                 if ($noticeData) {
                     $response = array('notice' => '', 'moduleID' => null, 'link' => $this->getOptionalModuleVar('BANNER_ALERT_MODULE_LINK', false, 'notice'));
                     // notice can either take a module or data model class or retriever class. The section is passed on. It must implement the HomeAlertInterface interface
                     if (isset($noticeData['BANNER_ALERT_MODULE'])) {
                         $moduleID = $noticeData['BANNER_ALERT_MODULE'];
                         $controller = WebModule::factory($moduleID);
                         $response['moduleID'] = $moduleID;
                         $string = "Module {$moduleID}";
                     } elseif (isset($noticeData['BANNER_ALERT_MODEL_CLASS'])) {
                         $controller = DataModel::factory($noticeData['BANNER_ALERT_MODEL_CLASS'], $noticeData);
                         $string = $noticeData['BANNER_ALERT_MODEL_CLASS'];
                     } elseif (isset($noticeData['BANNER_ALERT_RETRIEVER_CLASS'])) {
                         $controller = DataRetriever::factory($noticeData['BANNER_ALERT_RETRIEVER_CLASS'], $noticeData);
                         $string = $noticeData['BANNER_ALERT_RETRIEVER_CLASS'];
                     } else {
                         throw new KurogoConfigurationException("Banner alert not properly configured");
                     }
                     if (!$controller instanceof HomeAlertInterface) {
                         throw new KurogoConfigurationException("{$string} does not implement HomeAlertModule interface");
                     }
                     $response['notice'] = $controller->getHomeScreenAlert();
                 }
             }
             $this->setResponse($response);
             $this->setResponseVersion($responseVersion);
             break;
         case 'modules':
             if ($setcontext = $this->getArg('setcontext')) {
                 Kurogo::sharedInstance()->setUserContext($setcontext);
             }
             $responseVersion = 2;
             $response = array('primary' => array(), 'secondary' => array(), 'customize' => $this->getOptionalModuleVar('ALLOW_CUSTOMIZE', true), 'displayType' => $this->getOptionalModuleVar('display_type', 'springboard'));
             $allmodules = $this->getAllModules();
             $navModules = Kurogo::getSiteSections('navigation', Config::APPLY_CONTEXTS_NAVIGATION);
             foreach ($navModules as $moduleID => $moduleData) {
                 if ($module = Kurogo::arrayVal($allmodules, $moduleID)) {
                     $title = Kurogo::arrayVal($moduleData, 'title', $module->getModuleVar('title'));
                     $type = Kurogo::arrayVal($moduleData, 'type', 'primary');
                     $visible = Kurogo::arrayVal($moduleData, 'visible', 1);
                     $response[$type][] = array('tag' => $moduleID, 'title' => $title, 'visible' => (bool) $visible);
                 }
             }
             $this->setResponse($response);
             $this->setResponseVersion($responseVersion);
             break;
         default:
             $this->invalidCommand();
     }
 }
 protected function init($args)
 {
     parent::init($args);
     $this->pagetype = Kurogo::arrayVal($args, 'PAGETYPE', null);
     $this->platform = Kurogo::arrayVal($args, 'PLATFORM', null);
     $this->browser = Kurogo::arrayVal($args, 'BROWSER', null);
     if (strlen($this->pagetype) == 0 && strlen($this->platform) == 0 && strlen($this->browser) == 0) {
         throw new KurogoConfigurationException("PAGETYPE, PLATFORM or BROWSER must be specified in " . get_class($this));
     }
 }
 protected function getScheduleFeed($sport)
 {
     $scheduleData = $this->loadScheduleData();
     if ($feedData = Kurogo::arrayVal($scheduleData, $sport)) {
         $dataModel = Kurogo::arrayVal($feedData, 'MODEL_CLASS', self::$defaultEventModel);
         $this->scheduleFeed = AthleticEventsDataModel::factory($dataModel, $feedData);
         return $this->scheduleFeed;
     }
     return null;
 }
Exemplo n.º 6
0
 protected function init($args)
 {
     parent::init($args);
     $this->fieldMap = array('userid' => isset($args['KUROGO_USERID_FIELD']) ? $args['KUROGO_USERID_FIELD'] : 'uid', 'email' => isset($args['KUROGO_EMAIL_FIELD']) ? $args['KUROGO_EMAIL_FIELD'] : 'mail', 'fullname' => isset($args['KUROGO_FULLNAME_FIELD']) ? $args['KUROGO_FULLNAME_FIELD'] : '', 'firstname' => isset($args['KUROGO_FIRSTNAME_FIELD']) ? $args['KUROGO_FIRSTNAME_FIELD'] : 'givenname', 'lastname' => isset($args['KUROGO_LASTNAME_FIELD']) ? $args['KUROGO_LASTNAME_FIELD'] : 'sn', 'photodata' => isset($args['KUROGO_PHOTODATA_FIELD']) ? $args['KUROGO_PHOTODATA_FIELD'] : 'jpegphoto', 'phone' => isset($args['KUROGO_PHONE_FIELD']) ? $args['KUROGO_PHONE_FIELD'] : 'telephonenumber');
     if (isset($args['SORTFIELDS']) && is_array($args['SORTFIELDS'])) {
         $this->sortFields = $args['SORTFIELDS'];
     }
     if (isset($args['BASE_URL']) && $args['BASE_URL']) {
         $this->peopleAPI = rtrim($args['BASE_URL'], '/');
     }
     $this->feed = Kurogo::arrayVal($args, 'FEED');
     $this->setContext('fieldMap', $this->fieldMap);
 }
Exemplo n.º 7
0
 public static function factory($args)
 {
     if (!($class = Kurogo::arrayVal($args, 'RULE', 'CookieContextRule'))) {
         throw new KurogoConfigurationException("Context class must be specified in RULE key");
     }
     if (!class_exists($class)) {
         throw new KurogoConfigurationException("UserContextRule class {$class} not defined");
     }
     $rule = new $class();
     if (!$rule instanceof UserContextRule) {
         throw new KurogoConfigurationException(get_class($rule) . " is not a subclass of UserContextRule");
     }
     $rule->init($args);
     return $rule;
 }
 public function setContext($bool)
 {
     if ($this->value == UserContext::CONTEXT_DEFAULT) {
         if ($bool && isset($_COOKIE[$this->cookie])) {
             $this->clearCookie();
         }
         return true;
     }
     if ($bool) {
         Kurogo::log(LOG_DEBUG, "Setting CookieContext {$this->cookie} to {$this->value}", 'context');
         $this->setCookie();
     } elseif (Kurogo::arrayVal($_COOKIE, $this->cookie) == $this->value) {
         Kurogo::log(LOG_DEBUG, "Clearing CookieContext {$this->cookie} by {$this->value}", 'context');
         $this->clearCookie();
     }
     return true;
 }
Exemplo n.º 9
0
 public function parseEntry($entry)
 {
     if (isset($entry['entryId'])) {
         $video = new KalturaVideoObject();
         $video->setID($entry['entryId']);
         $video->setTitle($entry['title']);
         $video->setDescription($entry['description']);
         $ts = $entry['updatedAt'];
         // there is also a 'createdAt' property that could be used instead
         $video->setPublished(new DateTime("@{$ts}"));
         $video->setStillFrameImage($entry['thumbnail']['url']);
         $video->setImage($entry['thumbnailUrl']['url']);
         $video->setDuration($entry['media']['duration'] / 1000);
         // Need to convert to seconds
         $tags = Kurogo::arrayVal($entry, 'tags', array());
         $video->setTags(Kurogo::arrayVal($tags, 'tag', array()));
         // currently an array of tags
         $video->setVideoSources($entry['itemContent']);
         $video->setSubtitleTracks($entry['subTitles']);
         return $video;
     }
 }
Exemplo n.º 10
0
 protected function parseEntry($entry)
 {
     $video = new VimeoVideoObject();
     $video->setURL($entry['url']);
     if (isset($entry['mobile_url'])) {
         $video->setMobileURL($entry['mobile_url']);
     }
     $video->setTitle($entry['title']);
     $video->setDescription($entry['description']);
     $video->setDuration($entry['duration']);
     $video->setID($entry['id']);
     $video->setImage($entry['thumbnail_small']);
     $video->setStillFrameImage($entry['thumbnail_large']);
     if (isset($entry['tags'])) {
         $video->setTags($entry['tags']);
     }
     $video->setWidth(Kurogo::arrayVal($entry, 'width'));
     $video->setHeight(Kurogo::arrayVal($entry, 'height'));
     $video->setAuthor($entry['user_name']);
     $published = new DateTime($entry['upload_date']);
     $video->setPublished($published);
     return $video;
 }
Exemplo n.º 11
0
 private function loadSites()
 {
     //load sites.ini file
     $path = SITES_DIR . DIRECTORY_SEPARATOR . 'sites.ini';
     $sitesConfig = $this->baseConfigStore->loadConfig($path, 'file', Config::OPTION_IGNORE_SHARED);
     $sitesData = $sitesConfig->getSectionVars();
     if (count($sitesData) == 0) {
         throw new KurogoConfigurationException("No valid sites configured");
     }
     $sharedData = Kurogo::arrayVal($sitesData, 'shared', array());
     unset($sitesData['shared']);
     if (!defined('SERVER_KEY')) {
         $serverKey = Kurogo::arrayVal($sharedData, 'SERVER_KEY', md5(SITES_DIR));
         define('SERVER_KEY', $serverKey);
     }
     $sites = array();
     $multiSite = null;
     $default = null;
     foreach ($sitesData as $siteName => $siteData) {
         // [shared] section will be applied as common settings for all sites
         $siteData = array_merge($sharedData, $siteData);
         $site = new KurogoSite($siteName, $siteData);
         if ($site->isDefault()) {
             if (strlen($default)) {
                 throw new KurogoConfigurationException("Only 1 site can be labeled default, sites {$siteName} and {$default} set to default");
             }
             $default = $siteName;
         }
         $sites[$site->getName()] = $site;
     }
     $this->multiSite = count($sites) > 1;
     return $sites;
 }
Exemplo n.º 12
0
 private function getModuleCustomizeList()
 {
     $navModules = $this->getAllModuleNavigationData(self::INCLUDE_HIDDEN_MODULES, 'customize');
     $modules = Kurogo::arrayVal($navModules, 'primary', array());
     return $modules;
 }
Exemplo n.º 13
0
 protected function parseEntry($entry)
 {
     if (isset($entry['video']['id'])) {
         $entry = array_merge($entry, $entry['video']);
     }
     $video = new YouTubeVideoObject();
     $video->setURL($entry['player']['default']);
     if (isset($entry['content'][6])) {
         $video->setStreamingURL($entry['content'][6]);
     }
     if ($aspectRatio = Kurogo::arrayVal($entry, 'aspectRatio')) {
         if ($aspectRatio == 'widescreen') {
             $video->setAspectRatio(16 / 9);
         }
     }
     $video->setMobileURL($entry['content']['1']);
     $video->setTitle($entry['title']);
     $video->setDescription(strip_tags($entry['description']));
     $video->setDuration($entry['duration']);
     $video->setID($entry['id']);
     if (IS_SECURE) {
         $video->setImage(str_replace('http://', 'https://', $entry['thumbnail']['sqDefault']));
         $video->setStillFrameImage(str_replace('http://', 'https://', $entry['thumbnail']['hqDefault']));
     } else {
         $video->setImage($entry['thumbnail']['sqDefault']);
         $video->setStillFrameImage($entry['thumbnail']['hqDefault']);
     }
     if (isset($entry['tags'])) {
         $video->setTags($entry['tags']);
     }
     $video->setAuthor($entry['uploader']);
     $published = new DateTime($entry['uploaded']);
     $video->setPublished($published);
     return $video;
 }
Exemplo n.º 14
0
 public function messagingEnabled()
 {
     // if module doesn't specify messaging parameter, use site value
     $siteConfig = Kurogo::getOptionalSiteSection('notifications');
     $siteEnabled = Kurogo::arrayVal($siteConfig, 'ENABLED_BY_DEFAULT', false);
     return $this->getOptionalModuleVar('messaging', $siteEnabled, null, 'module');
 }
Exemplo n.º 15
0
 public function initializeForCommand()
 {
     $this->feeds = $this->loadFeedData();
     $feed = $this->getArg('feed', $this->getDefaultFeed());
     $this->loadAPIDetailAttributes($feed);
     $peopleController = $this->getFeed($feed);
     $output = $this->getArg('output', '');
     switch ($this->command) {
         case 'search':
             if ($filter = $this->getArg(array('filter', 'q'))) {
                 $this->setLogData($filter);
                 $people = $peopleController->search($filter);
                 if (!$people) {
                     $people = array();
                 }
                 $hasError = $peopleController->getResponseError();
                 if ($hasError) {
                     // TODO decide on error title
                     $errorTitle = 'Warning';
                     $errorMsg = $peopleController->getResponseError();
                     $errorCode = $peopleController->getResponseCode();
                     $error = new KurogoError($errorCode, $errorTitle, $errorMsg);
                 }
                 $response[] = null;
                 if ($people !== false) {
                     $results = array();
                     $resultCount = count($people);
                     foreach ($people as $person) {
                         $results[] = $this->formatPerson($person, $output);
                     }
                     $response = array('total' => $resultCount, 'returned' => $resultCount, 'feed' => $feed, 'displayField' => 'name', 'results' => $results, 'requiresDetail' => (bool) $this->getOptionalModuleVar('API_REQUIRES_DETAIL'), 'error' => isset($error) ? $error : null);
                 }
                 $this->setResponse($response);
                 $this->setResponseVersion(2);
             } else {
                 $this->invalidCommand();
                 $this->setResponseVersion(1);
             }
             break;
         case 'detail':
             if ($uid = $this->getArg(array('id', 'uid'))) {
                 $person = $peopleController->getUser($uid);
                 if ($person) {
                     $personDetails = $this->formatPerson($person, $output);
                     $response = array('person' => $personDetails);
                     $this->setResponse($response);
                     $this->setResponseVersion(1);
                 } else {
                     $hasError = $peopleController->getResponseError();
                     if ($hasError) {
                         // TODO decide on error title
                         $errorTitle = 'Warning';
                         $errorMsg = $peopleController->getResponseError();
                         $errorCode = $peopleController->getResponseCode();
                         $error = new KurogoError($errorCode, $errorTitle, $errorMsg);
                         $this->setResponseError($error);
                     }
                 }
             } else {
                 $this->invalidCommand();
                 $this->setResponseVersion(1);
             }
             break;
         case 'contacts':
             $convertTags = array('class' => 'type', 'label' => 'title', 'value' => 'subtitle');
             $group = $this->getArg('group');
             if ($group) {
                 $results = $this->getContactsForGroup($group);
             } else {
                 $results = $this->getModuleSections('api-contacts');
             }
             foreach ($results as &$aResult) {
                 if (isset($aResult['group'])) {
                     $groupData = $this->getContactGroup($aResult['group']);
                     if (isset($groupData['description'])) {
                         $aResult['subtitle'] = $groupData['description'];
                     }
                 }
                 foreach ($convertTags as $from => $to) {
                     if (isset($aResult[$from])) {
                         $aResult[$to] = $aResult[$from];
                         unset($aResult[$from]);
                     }
                 }
             }
             $response = array('total' => count($results), 'results' => $results);
             $this->setResponse($response);
             $this->setResponseVersion(1);
             break;
         case 'group':
             $group = $this->getContactGroup($this->getArg('group'));
             $response = array('total' => count($group), 'results' => $group);
             $this->setResponse($response);
             $this->setResponseVersion(1);
             break;
         case 'displayfields':
             //break;
         //break;
         case 'feeds':
             $feeds = array();
             foreach ($this->feeds as $key => $feedData) {
                 $feeds[] = array('feed' => $key, 'title' => Kurogo::arrayVal($feedData, 'TITLE', $feed));
             }
             $response = $feeds;
             $this->setResponse($response);
             $this->setResponseVersion(1);
             break;
         default:
             $this->invalidCommand();
             break;
     }
 }
Exemplo n.º 16
0
 private function __construct()
 {
     # populate flashes from session
     $this->flashes = Kurogo::arrayVal($_SESSION, $this->key);
 }
Exemplo n.º 17
0
function mapIdForFeedData(array $feedData)
{
    $identifier = Kurogo::arrayVal($feedData, 'TITLE', '');
    if (isset($feedData['BASE_URL'])) {
        $identifier .= $feedData['BASE_URL'];
    } else {
        Kurogo::log(LOG_WARNING, "Warning: map feed for {$identifier} has no BASE_URL for map feed", 'maps');
    }
    return substr(md5($identifier), 0, 10);
}
Exemplo n.º 18
0
 protected function initializeSchedule()
 {
     $locationID = $this->getArg('section');
     $eventID = $this->getArg('id');
     $feedID = $this->getArg('groupID');
     $model = $this->loadFeed($feedID);
     $location = $model->getLocation($locationID);
     $locationEvents = $location->getAttribute('events');
     $time = $this->getArg('time', time(), FILTER_VALIDATE_INT);
     if ($event = $locationEvents->getItem($eventID, $time)) {
         $this->assign('event', $event);
     } else {
         throw new KurogoUserException($this->getLocalizedString('EVENT_NOT_FOUND'));
     }
     $eventFields = $this->getModuleSections('schedule-detail');
     $fields = array();
     foreach ($eventFields as $key => $info) {
         $field = array();
         $value = $event->get_attribute($key);
         if (empty($value)) {
             continue;
         }
         if (isset($info['label'])) {
             $field['label'] = $info['label'];
         }
         if (isset($info['class'])) {
             $field['class'] = $info['class'];
         }
         if (Kurogo::arrayVal($info, 'nl2br')) {
             $value = nl2br($value);
         }
         if (isset($info['type'])) {
             $field['title'] = $this->valueForType($info['type'], $value);
             $field['url'] = $this->urlForType($info['type'], $value);
         } elseif (isset($info['module'])) {
             $field = array_merge($field, Kurogo::moduleLinkForValue($info['module'], $value, $this, $event));
         } else {
             $field['title'] = $value;
         }
         $fields[] = $field;
     }
     $this->assign('fields', $fields);
 }
Exemplo n.º 19
0
 public function setMediaGroup($group)
 {
     if ($thumbnail = Kurogo::arrayVal($group, 'thumbnail')) {
         $this->setThumbnail($thumbnail);
     }
     if ($image = Kurogo::arrayVal($group, 'image')) {
         $this->setImage($image);
     }
 }
Exemplo n.º 20
0
 public function init($args)
 {
     parent::init($args);
     if (isset($args['ITEM_CLASS'])) {
         $this->setItemClass($args['ITEM_CLASS']);
     }
     if (isset($args['IMAGE_CLASS'])) {
         $this->setImageClass($args['IMAGE_CLASS']);
     }
     if (isset($args['USE_DESCRIPTION_FOR_CONTENT'])) {
         $this->setUseDescriptionForContent($args['USE_DESCRIPTION_FOR_CONTENT']);
     }
     $this->userFields = Kurogo::arrayVal($args, 'FIELDS', array());
 }
Exemplo n.º 21
0
 public function initializeForCommand()
 {
     switch ($this->command) {
         case 'hello':
             $allmodules = $this->getAllModules();
             if ($this->requestedVersion >= 3) {
                 $version = 3;
             } else {
                 $version = 2;
                 $homeModuleData = $this->getAllModuleNavigationData();
                 $homeModules = array('primary' => array_keys($homeModuleData['primary']), 'secondary' => array_keys($homeModuleData['secondary']));
             }
             $platform = $this->clientPlatform;
             if ($this->clientPagetype == 'tablet') {
                 $platform .= '-tablet';
             }
             foreach ($allmodules as $moduleID => $module) {
                 if ($module->isEnabled()) {
                     //home is deprecated in lieu of using the "modules" command of the home module
                     $home = false;
                     if ($version < 3) {
                         if (($key = array_search($moduleID, $homeModules['primary'])) !== FALSE) {
                             if (Kurogo::arrayVal($homeModuleData['primary'][$moduleID], 'visible', true)) {
                                 $title = Kurogo::arrayVal($homeModuleData['primary'][$moduleID], 'title', $module->getModuleVar('title'));
                                 $home = array('type' => 'primary', 'order' => $key, 'title' => $title);
                             }
                         } elseif (($key = array_search($moduleID, $homeModules['secondary'])) !== FALSE) {
                             if (Kurogo::arrayVal($homeModuleData['secondary'][$moduleID], 'visible', true)) {
                                 $title = Kurogo::arrayVal($homeModuleData['secondary'][$moduleID], 'title', $module->getModuleVar('title'));
                                 $home = array('type' => 'secondary', 'order' => $key, 'title' => $title);
                             }
                         }
                     }
                     $moduleResponse = array('id' => $module->getID(), 'tag' => $module->getConfigModule(), 'icon' => $module->getOptionalModuleVar('icon', $module->getConfigModule(), 'module'), 'title' => $module->getModuleVar('title', 'module'), 'access' => $module->getAccess(AccessControlList::RULE_TYPE_ACCESS), 'payload' => $module->getPayload(), 'bridge' => $module->getWebBridgeConfig($platform), 'vmin' => $module->getVmin(), 'vmax' => $module->getVmax());
                     if ($version < 3) {
                         $moduleResponse['home'] = $home;
                     }
                     $modules[] = $moduleResponse;
                 }
             }
             $contexts = array();
             foreach (Kurogo::sharedInstance()->getContexts() as $context) {
                 if ($context->isManual()) {
                     $contexts[] = array('id' => $context->getID(), 'title' => $context->getTitle(), 'description' => $context->getDescription());
                 }
             }
             $response = array('timezone' => Kurogo::getSiteVar('LOCAL_TIMEZONE'), 'site' => Kurogo::getSiteString('SITE_NAME'), 'organization' => Kurogo::getSiteString('ORGANIZATION_NAME'), 'version' => KUROGO_VERSION, 'modules' => $modules, 'default' => Kurogo::defaultModule(), 'home' => $this->getHomeModuleID(), 'contexts' => $contexts, 'contextsDisplay' => array('home' => Kurogo::getSiteVar('USER_CONTEXT_LIST_STYLE_NATIVE', 'contexts'), 'customize' => Kurogo::getSiteVar('USER_CONTEXT_LIST_STYLE_CUSTOMIZE', 'contexts')));
             if ($appData = Kurogo::getAppData($this->clientPlatform)) {
                 if ($version = Kurogo::arrayVal($appData, 'version')) {
                     if (version_compare($this->clientVersion, $version) < 0) {
                         $response['appdata'] = array('url' => Kurogo::arrayVal($appData, 'url'), 'version' => Kurogo::arrayVal($appData, 'version'));
                     }
                 }
             }
             $this->setResponse($response);
             $this->setResponseVersion($version);
             break;
         case 'setcontext':
             $context = $this->getArg('context');
             $response = Kurogo::sharedInstance()->setUserContext($context);
             $this->setResponse($response);
             $this->setResponseVersion(1);
             break;
         case 'classify':
             $userAgent = $this->getArg('useragent');
             if (!$userAgent) {
                 throw new KurogoException("useragent parameter not specified");
             }
             $response = Kurogo::deviceClassifier()->classifyUserAgent($userAgent);
             $this->setResponse($response);
             $this->setResponseVersion(1);
             break;
         default:
             $this->invalidCommand();
             break;
     }
 }
 protected function getSearchFeeds()
 {
     $feeds = array();
     foreach ($this->feeds as $feed => $feedData) {
         $feeds[$feed] = Kurogo::arrayVal($feedData, 'TITLE', $feed);
     }
     return $feeds;
 }
 public function parseData($data)
 {
     if ($data = json_decode($data, true)) {
         if (is_array($data)) {
             $action = $this->getOption('action');
             switch ($action) {
                 case 'user':
                     return $this->parseUser($data);
                     break;
                 case 'posts':
                     $return = array();
                     $posts = Kurogo::arrayVal($data, 'data', array());
                     foreach ($posts as $entry) {
                         $post = $this->parsePost($entry);
                         if ($post->getBody()) {
                             $return[] = $post;
                         }
                     }
                     return $return;
                     break;
                 case 'post':
                     return $this->parsePost($data);
                     break;
             }
         }
     }
     return null;
 }
Exemplo n.º 24
0
 private function getModules()
 {
     $modulesNavData = $this->getAllModuleNavigationData();
     $modules = array('primary' => array(), 'secondary' => array(), 'unused' => array());
     foreach ($modulesNavData as $type => $typeModules) {
         foreach ($typeModules as $moduleID => $moduleNavData) {
             $modules[$type][$moduleID] = $moduleNavData['title'];
         }
     }
     $usedModules = array_merge($modules['primary'], $modules['secondary']);
     $allModules = $this->getAllModules();
     $unusedModules = array_diff(array_keys($allModules), array_keys($usedModules));
     if ($iconSet = $this->getOptionalThemeVar('navigation_icon_set')) {
         $iconSetSize = $this->getOptionalThemeVar('navigation_icon_size');
         $imgPrefix = "/common/images/iconsets/{$iconSet}/{$iconSetSize}/";
     } else {
         $imgPrefix = "/modules/{$homeModuleID}/images/";
     }
     foreach ($unusedModules as $moduleID) {
         $module = $allModules[$moduleID];
         if ($module->canBeAddedToHomeScreen()) {
             $modules['unused'][$moduleID] = $module->getModuleName();
         }
     }
     foreach ($modules as $type => &$m) {
         foreach ($m as $id => $title) {
             if ($module = Kurogo::arrayVal($allModules, $id)) {
                 $icon = $module->getOptionalModuleVar('icon', $module->getConfigModule(), 'module');
                 $modules[$type][$id] = array('title' => $title, 'img' => sprintf("%s%s%s", $imgPrefix, $icon, $this->imageExt));
             } else {
                 unset($modules[$type][$id]);
             }
         }
     }
     return $modules;
 }
Exemplo n.º 25
0
 /**
  * Factory method. Used to instantiate a subclass
  * @param string $id, the module id to load
  * @param string $type, the type of module to load (web/api)
  */
 public static function factory($id, $type = null)
 {
     if ($id == 'kurogo') {
         set_exception_handler("exceptionHandlerForError");
     }
     if (!self::isValidModuleName($id)) {
         throw new KurogoException(Kurogo::getLocalizedString('ERROR_INVALID_MODULE'));
     }
     Kurogo::log(LOG_INFO, "Initializing {$type} module {$id}", 'module');
     $configModule = $id;
     $configStore = Kurogo::configStore();
     //attempt to load config/$id/module.ini
     if ($moduleData = $configStore->getOptionalSection('module', 'module', $configModule)) {
         $id = Kurogo::arrayVal($moduleData, 'id', $configModule);
     } else {
         throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
     }
     // see if the class location has been cached
     if ($moduleFile = Kurogo::getCache(self::cacheKey($id, $type))) {
         $className = basename($moduleFile, '.php');
         include_once $moduleFile;
         $module = new $className();
         if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
             $module->setID($id);
         }
         $module->setConfigModule($configModule);
         Kurogo::addModuleLib($id);
         return $module;
     }
     // when run without a type it will find either
     $classNames = array('web' => ucfirst($id) . 'WebModule', 'api' => ucfirst($id) . 'APIModule', 'shell' => ucfirst($id) . 'ShellModule');
     // if we specified a type, include only that type in the array
     if ($type) {
         if (isset($classNames[$type])) {
             $classNames = array($classNames[$type]);
         } else {
             throw new KurogoException("Invalid module type {$type}");
         }
     }
     // possible module paths.
     // 1. Site Folder SiteMODULEIDXXXModule
     // 2. Site Folder MODULEIDXXXModule
     // 3. Project folder MODULEIDXXXModule
     // Note: The PHP class name MUST be the basename of the file path.
     $modulePaths = array(SITE_MODULES_DIR . "/{$id}/Site%s.php", SITE_MODULES_DIR . "/{$id}/%s.php", SHARED_MODULES_DIR . "/{$id}/Site%s.php", SHARED_MODULES_DIR . "/{$id}/%s.php", MODULES_DIR . "/{$id}/%s.php");
     if ($type == 'api' && KurogoWebBridge::moduleHasMediaAssets($configModule)) {
         $modulePaths[] = LIB_DIR . '/' . KurogoWebBridge::STUB_API_CLASS . ".php";
     }
     //cycle module paths
     foreach ($modulePaths as $path) {
         $className = basename($path, '.php');
         //cycle class names to find a valid module
         foreach ($classNames as $class) {
             $className = sprintf($className, $class);
             $path = sprintf($path, $class);
             Kurogo::log(LOG_DEBUG, "Looking for {$path} for {$id}", 'module');
             // see if it exists
             $moduleFile = realpath_exists($path);
             if ($moduleFile && (include_once $moduleFile)) {
                 //found it
                 $info = new ReflectionClass($className);
                 if (!$info->isAbstract()) {
                     Kurogo::log(LOG_INFO, "Found {$moduleFile} for {$id}", 'module');
                     $module = new $className();
                     if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
                         $module->setID($id);
                     }
                     $module->setConfigModule($configModule);
                     // cache the location of the class (which also includes the classname)
                     Kurogo::setCache(self::cacheKey($id, $type), $moduleFile);
                     Kurogo::addModuleLib($id);
                     return $module;
                 }
                 Kurogo::log(LOG_NOTICE, "{$class} found at {$moduleFile} is abstract and cannot be used for {$id}", 'module');
                 return false;
             }
         }
     }
     Kurogo::log(LOG_NOTICE, "No valid {$type} class found for module {$id}", 'module');
     throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
 }
 protected function formatDetailFieldInfo($value, $info, KurogoDataObject $object)
 {
     // if the value is empty then see if there is a ifBlankfield
     if (is_null($value) || is_string($value) && strlen($value) == 0) {
         if (isset($info['ifBlank'])) {
             $info['title'] = $info['ifBlank'];
             $info['titlefield'] = null;
         } else {
             return null;
         }
     }
     $type = Kurogo::arrayVal($info, 'type', 'text');
     if (is_array($value)) {
         if (isset($info['format'])) {
             $value = vsprintf($this->replaceFormat($info['format']), $value);
         } else {
             $delimiter = isset($info['delimiter']) ? $info['delimiter'] : ' ';
             $value = implode($delimiter, $value);
         }
     } elseif (is_object($value)) {
         if ($type == 'date') {
             if (!$value instanceof DateTime) {
                 throw new KurogoDataException("Date type must be an instance of DateTime");
             }
             $value = $value->format('U');
         } else {
             throw new KurogoDataException("Value is an object. This needs to be traced");
         }
     }
     $detail = $info;
     foreach (array('title', 'subtitle', 'label', 'url', 'class', 'img', 'listclass', 'imagealt', 'imageheight', 'imagewidth') as $attrib) {
         if (isset($info[$attrib . 'field'])) {
             $detail[$attrib] = $this->getObjectField($object, $info[$attrib . 'field']);
         }
     }
     if (!isset($detail['class'])) {
         $detail['class'] = '';
     }
     switch ($type) {
         case 'email':
             if (!isset($detail['title'])) {
                 $detail['title'] = str_replace('@', '@&shy;', $value);
             }
             $detail['url'] = "mailto:{$value}";
             $detail['class'] = trim(Kurogo::arrayVal($detail, 'class', '') . ' email');
             break;
         case 'phone':
             if (!isset($detail['title'])) {
                 $detail['title'] = str_replace('-', '-&shy;', $value);
             }
             if (strpos($value, '+1') !== 0) {
                 $value = "+1{$value}";
             }
             $detail['url'] = PhoneFormatter::getPhoneURL($value);
             $detail['class'] = trim(Kurogo::arrayVal($detail, 'class', '') . ' phone');
             break;
         case 'currency':
             if (!isset($detail['title'])) {
                 $detail['title'] = sprintf("\$%s", number_format($value, 2));
             }
             break;
         case 'date':
             if (!isset($detail['title'])) {
                 $format = Kurogo::arrayVal($detail, 'format', '%m/%d/%Y');
                 $detail['title'] = strftime($format, $value);
             }
             break;
         case 'text':
             if (!isset($detail['title'])) {
                 $detail['title'] = nl2br(trim($value));
             }
             break;
         case 'image':
             $url = $value;
             $alt = Kurogo::arrayVal($detail, 'imagealt');
             if ($height = Kurogo::arrayVal($detail, 'imageheight')) {
                 $height = sprintf('height="%d"', $height);
             }
             if ($width = Kurogo::arrayVal($detail, 'imagewidth')) {
                 $width = sprintf('width="%d"', $width);
             }
             if (!isset($detail['title'])) {
                 $detail['title'] = sprintf('<img src="%s" alt="%s" %s %s class="detailimage" />', $value, htmlentities($alt), $height, $width);
             }
             break;
         default:
             throw new KurogoConfigurationException("Unhandled type {$type}");
             break;
     }
     if (isset($info['module'])) {
         $modValue = $value;
         if (isset($info['value'])) {
             $modValue = $this->getObjectField($object, $info['value']);
         }
         $moduleLink = Kurogo::moduleLinkForValue($info['module'], $modValue, $this->module, $object);
         $detail = array_merge($moduleLink, $detail);
         $detail['class'] .= " " . Kurogo::arrayVal($moduleLink, 'class');
     } elseif (isset($info['page'])) {
         $pageValue = $value;
         if (isset($info['value'])) {
             $pageValue = $this->getObjectField($object, $info['value']);
         }
         $pageLink = $this->module->pageLinkForValue($info['page'], $pageValue, $object);
         $detail = array_merge($pageLink, $detail);
         $detail['class'] .= " " . Kurogo::arrayVal($pageLink, 'class');
     }
     return $detail;
 }
Exemplo n.º 27
0
 private static function timezoneFilter($tzid)
 {
     static $timezoneMap;
     if (!$timezoneMap) {
         $timezoneMap = Kurogo::getSiteSection('timezones');
     }
     return Kurogo::arrayVal($timezoneMap, $tzid, $tzid);
 }
Exemplo n.º 28
0
 public function getCredentials(AuthenticationAuthority $authority)
 {
     $value = null;
     if ($cache = Kurogo::arrayVal($_SESSION, 'KurogoCredentialsCache')) {
         $value = Kurogo::arrayVal($cache, $authority->getAuthorityIndex());
     }
     try {
         $credentials = Kurogo::decrypt($value);
     } catch (KurogoException $e) {
         $credentials = $value;
     }
     return $credentials;
 }
Exemplo n.º 29
0
 protected function getUserNavData()
 {
     if ($this->getArg('resetUserNavData')) {
         $this->resetUserNavData();
     }
     if ($userNavData = Kurogo::arrayVal($_COOKIE, self::MODULE_NAV_COOKIE)) {
         $data = json_decode($userNavData, true);
         if (is_array($data)) {
             $userNavData = array('visible' => $data);
         } else {
             $userNavData = null;
         }
     }
     return $userNavData;
 }
Exemplo n.º 30
0
 protected function getFeedsByType(&$totalFeeds)
 {
     $feeds = array();
     $totalFeeds = 0;
     foreach (array('user', 'resource', 'static') as $type) {
         $typeFeeds = $this->getFeeds($type);
         foreach ($typeFeeds as $feed => $feedData) {
             $enableSearch = Kurogo::arrayVal($feedData, 'ENABLE_SEARCH', true);
             if ($enableSearch) {
                 $totalFeeds++;
                 $feeds[$type][$type . '|' . $feed] = $feedData['TITLE'];
             }
         }
     }
     return $feeds;
 }