Example #1
0
 /**
  * Channels restful api
  */
 public function action_manage()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     switch ($this->request->method()) {
         case "POST":
             $channel_array = json_decode($this->request->body(), TRUE);
             $channel_config = Swiftriver_Plugins::get_channel_config($channel_array['channel']);
             if (!$channel_config) {
                 throw new HTTP_Exception_400();
             }
             $channel_orm = $this->river->get_channel($channel_array['channel']);
             // Make sure the channel is enabled for the case where a disabled
             // channel is being re-added.
             if (!(bool) $channel_orm->filter_enabled) {
                 $channel_orm->filter_enabled = TRUE;
                 $channel_orm->save();
             }
             echo json_encode(array('id' => $channel_orm->id, 'channel' => $channel_orm->channel, 'name' => $channel_config['name'], 'enabled' => (bool) $channel_orm->filter_enabled, 'options' => $this->river->get_channel_options($channel_orm)));
             break;
         case "PUT":
             $channel_array = json_decode($this->request->body(), TRUE);
             $channel_orm = $this->river->get_channel($channel_array['channel']);
             $channel_orm->filter_enabled = $channel_array['enabled'];
             $channel_orm->save();
             break;
         case "DELETE":
             $channel_id = intval($this->request->param('id', 0));
             $channel_orm = $this->river->get_channel_by_id($channel_id);
             if ($channel_orm) {
                 $channel_orm->delete();
             }
             break;
     }
 }
Example #2
0
 /**
  * Application initialization
  *     - Loads the plugins
  *     - Sets the cookie configuration
  */
 public static function init()
 {
     // Set defaule cache configuration
     Cache::$default = Kohana::$config->load('site')->get('default_cache');
     try {
         $cache = Cache::instance()->get('dummy' . rand(0, 99));
     } catch (Exception $e) {
         // Use the dummy driver
         Cache::$default = 'dummy';
     }
     // Load the plugins
     Swiftriver_Plugins::load();
     // Add the current default theme to the list of modules
     $theme = Swiftriver::get_setting('site_theme');
     if (isset($theme) and $theme != "default") {
         Kohana::modules(array_merge(array('themes/' . $theme->value => THEMEPATH . $theme->value), Kohana::modules()));
     }
     // Clean up
     unset($active_plugins, $theme);
     // Load the cookie configuration
     $cookie_config = Kohana::$config->load('cookie');
     Cookie::$httponly = TRUE;
     Cookie::$salt = $cookie_config->get('salt', Swiftriver::DEFAULT_COOKIE_SALT);
     Cookie::$domain = $cookie_config->get('domain') or '';
     Cookie::$secure = $cookie_config->get('secure') or FALSE;
     Cookie::$expiration = $cookie_config->get('expiration') or 0;
     // Set the default site locale
     I18n::$lang = Swiftriver::get_setting('site_locale');
 }
Example #3
0
 /**
  * @return	void
  */
 public function before()
 {
     // Execute parent::before first
     parent::before();
     // Get the river name from the url
     $river_name_url = $this->request->param('name');
     $action = $this->request->action();
     // Find the matching river from the visited account's rivers.
     if (($river = $this->account_service->has_river($this->visited_account, $river_name_url)) !== FALSE) {
         $this->river = $this->river_service->get_river_by_id($river['id'], $this->user);
     }
     if ($river_name_url and !$this->river and $action != 'manage') {
         $this->redirect($this->dashboard_url, 302);
     }
     // Action involves a specific river, check permissions
     if ($this->river) {
         $this->owner = $this->river['is_owner'] or $this->river['is_collaborator'];
         $this->is_collaborator = $this->river['is_collaborator'];
         $this->public = (bool) $this->river['public'];
         // If this river is not public and no ownership...
         if (!$this->public and !$this->owner and !$this->is_collaborator) {
             $this->redirect($this->dashboard_url, 302);
         }
         $this->river_base_url = $this->river_service->get_base_url($this->river);
         $this->settings_url = $this->river_base_url . '/settings';
         // Navigation Items
         $this->nav = Swiftriver_Navs::river($this->river);
         if ($this->owner) {
             $this->page_title = $this->river['name'];
         } else {
             $this->page_title = $this->river['account']['account_path'] . ' / ' . $this->river['name'];
         }
         $this->template->header->title = $this->page_title;
         $this->template->content = View::factory('pages/river/layout')->bind('droplets_view', $this->droplets_view)->bind('river_base_url', $this->river_base_url)->bind('settings_url', $this->settings_url)->bind('owner', $this->owner)->bind('anonymous', $this->anonymous)->bind('user', $this->user)->bind('nav', $this->nav)->bind('active', $this->active)->bind('page_title', $this->page_title)->bind('follow_button', $follow_button)->bind('is_collaborator', $this->is_collaborator);
         $view_data = array('channels_config' => json_encode(Swiftriver_Plugins::channels()), 'channels' => json_encode($this->river['channels']), 'channels_base_url' => $this->river_base_url . '/settings/channels/options', 'river' => $this->river);
         $this->template->content->set($view_data);
         $this->template->header->js .= HTML::script("themes/default/media/js/channels.js");
         // Show the follow button?
         if (!$this->owner and !$this->is_collaborator) {
             $is_following = $this->river_service->is_follower($this->river['id'], $this->user['id']);
             $river_data = json_encode(array('id' => $this->river['id'], 'name' => $this->river['name'], 'type' => 'river', 'following' => $is_following));
             $follow_button = View::factory('template/follow')->bind('data', $river_data)->bind('action_url', $action_url);
             $action_url = URL::site($this->river['url'] . '/manage');
         }
     }
 }
Example #4
0
 /**
  * Channel options restful api
  */
 public function action_options()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     sleep(5);
     switch ($this->request->method()) {
         case "DELETE":
             $channel_id = intval($this->request->param('id', 0));
             $this->river_service->delete_channel($this->river['id'], $channel_id);
             break;
         case "POST":
             $channel_array = json_decode($this->request->body(), TRUE);
             $channel_config = Swiftriver_Plugins::get_channel_config($channel_array['channel']);
             if (!$channel_config) {
                 throw new HTTP_Exception_400();
             }
             try {
                 $channel_array = $this->river_service->create_channel_from_array($this->river['id'], $channel_array);
                 echo json_encode($channel_array);
             } catch (Swiftriver_Exception_Channel_Option $e) {
                 $this->response->status(400);
                 $this->response->headers('Content-Type', 'application/json');
                 echo json_encode(array('error' => $e->getMessage()));
             }
             break;
         case "PUT":
             $channel_id = intval($this->request->param('id', 0));
             $channel_array = json_decode($this->request->body(), TRUE);
             $channel_config = Swiftriver_Plugins::get_channel_config($channel_array['channel']);
             if (!$channel_config) {
                 throw new HTTP_Exception_400();
             }
             try {
                 $channel_array = $this->river_service->update_channel_from_array($this->river['id'], $channel_id, $channel_array);
                 echo json_encode($channel_array);
             } catch (Swiftriver_Exception_Channel_Option $e) {
                 $this->response->status(400);
                 $this->response->headers('Content-Type', 'application/json');
                 echo json_encode(array('error' => $e->getMessage()));
             }
             break;
         default:
             throw new HTTP_Exception_405();
     }
 }
Example #5
0
 /**
  * Private function to go through plugin directory and extract
  * plugins in the system, then save them in the database
  * so that they're available for activation in admin
  *
  * @return	void
  */
 private function _process_plugins()
 {
     $configs = Swiftriver_Plugins::load_configs();
     // Sync the folder with the database
     foreach ($configs as $key => $value) {
         if (ORM::factory('Plugin')->where('plugin_path', '=', $key)->count_all() == 0) {
             $plugin = ORM::factory('Plugin');
             $plugin->plugin_path = $key;
             $plugin->plugin_name = $value['name'];
             $plugin->plugin_description = $value['description'];
             $plugin->save();
         }
     }
     // Remove Any Plugins not found in the plugins folder from the database
     foreach (ORM::factory('Plugin')->find_all() as $plugin) {
         if (!array_key_exists($plugin->plugin_path, $configs)) {
             $plugin->delete();
         }
     }
 }
Example #6
0
 /**
  * Return a river array with subscription and collaboration
  * status populated for $querying_account
  *
  * @param Model_User $user
  * @param Model_User $querying_account
  * @return array
  *
  */
 public static function get_array($river, $querying_account)
 {
     $river['url'] = self::get_base_url($river);
     $river['expired'] = FALSE;
     $river['is_owner'] = $river['account']['id'] == $querying_account['id'];
     // Calculate % of the river that is occupied
     $drop_count = $river['drop_count'];
     $drop_quota = $river['drop_quota'];
     $percent_full = ($drop_count > 0 and $drop_quota > 0) ? round($drop_count / $drop_quota * 100, 2) : 0;
     $river['percent_full'] = $percent_full;
     // Is the querying account collaborating on the river?
     $river['is_collaborator'] = FALSE;
     foreach ($querying_account['collaborating_rivers'] as $r) {
         if ($river['id'] == $r['id']) {
             // $river['is_owner'] = TRUE;
             $river['is_collaborator'] = TRUE;
         }
     }
     // Is the querying account following the river?
     $river['following'] = FALSE;
     foreach ($querying_account['following_rivers'] as $r) {
         if ($river['id'] == $r['id']) {
             $river['following'] = TRUE;
         }
     }
     // Get display name from channel plugins and disabled channels
     if (isset($river['channels'])) {
         $channels = array();
         foreach ($river['channels'] as $channel) {
             if (!Swiftriver_Plugins::get_channel_config($channel['channel'])) {
                 continue;
             }
             $channel['display_name'] = '';
             $channel['parameters'] = json_decode($channel['parameters'], TRUE);
             Swiftriver_Event::run('swiftriver.channel.format', $channel);
             $channels[] = $channel;
         }
         $river['channels'] = $channels;
     }
     return $river;
 }
Example #7
0
 /**
  * Create a New River
  * Step 2 - Open Channels
  * @return	void
  */
 public function action_open()
 {
     $this->step_content = View::factory('pages/river/settings/channels');
     $this->step = 'open';
     // This River
     $id = $this->request->param('id', 0);
     $river = ORM::factory('river', $id);
     if (!$river->loaded()) {
         $this->request->redirect(URL::site() . $this->account_path . '/river/create');
     }
     $this->step_content->channels_config = json_encode(Swiftriver_Plugins::channels());
     $this->step_content->channels = json_encode($river->get_channels(TRUE));
     $this->step_content->base_url = $river->get_base_url() . '/settings/channels';
     // Open Url
     $this->open_url = URL::site() . $this->account_path . '/river/create/open/' . $river->id;
     // View Url
     $this->view_url = URL::site() . $this->account_path . '/river/create/view/' . $river->id;
 }
Example #8
0
 /**
  * Get a river's channel options with configuration added
  *
  * @param Model_Channel_Filter $channel_orm 
  * @param int $id Id of channel filter to be returned
  * @return array
  */
 public function get_channel_options($channel_orm, $id = NULL)
 {
     $options = array();
     $channel_config = Swiftriver_Plugins::get_channel_config($channel_orm->channel);
     $query = $channel_orm->channel_filter_options;
     if ($id) {
         $query->where('id', '=', $id);
     }
     foreach ($query->find_all() as $channel_option) {
         $option = json_decode($channel_option->value);
         $option->id = $channel_option->id;
         $option->key = $channel_option->key;
         if (!isset($channel_config['options'][$channel_option->key])) {
             continue;
         }
         $options[] = $option;
     }
     return $options;
 }
Example #9
0
 /**
  * Find all the active plugins with channel services
  *
  * @param   bool $reload Reloads the channel configs when TRUE
  * @return	array $channels
  */
 public static function channels($reload = FALSE)
 {
     if (!$reload and !empty(self::$channels)) {
         return self::$channels;
     }
     self::$channels = array();
     // Load the plugin configs and fetch only those that
     // have the channel property set to TRUE
     $config_plugins = Kohana::$config->load('plugin');
     $active_plugins = Kohana::$config->load('site')->get('plugins');
     foreach ($active_plugins as $active_plugin) {
         if (!isset($config_plugins[$active_plugin])) {
             continue;
         }
         $plugin_config = $config_plugins[$active_plugin];
         if (isset($plugin_config['channel']) and $plugin_config['channel'] == TRUE) {
             $channel_config = self::_validate_channel_plugin_config($plugin_config);
             if (!isset($channel_config)) {
                 continue;
             }
             self::$channels[] = array('name' => $plugin_config['name'], 'channel' => $active_plugin, 'options' => $channel_config);
         }
     }
     return self::$channels;
 }
Example #10
0
 /**
  * Find all the active plugins with channel services
  *
  * @param   bool $reload Reloads the channel configs when TRUE
  * @return	array $channels
  */
 public static function channels($reload = FALSE)
 {
     if (!$reload and !empty(self::$channels)) {
         return self::$channels;
     }
     self::$channels = array();
     // Load the plugin configs and fetch only those that
     // have the channel property set to TRUE
     $config_plugins = Kohana::$config->load('plugin');
     $active_plugins = ORM::factory('plugin')->where('plugin_enabled', '=', '1')->find_all();
     foreach ($active_plugins as $active_plugin) {
         $plugin_config = $config_plugins[$active_plugin->plugin_path];
         if (isset($plugin_config['channel']) and $plugin_config['channel'] == TRUE) {
             if (!($channel_config = self::_validate_channel_plugin_config($plugin_config))) {
                 continue;
             }
             self::$channels[] = array('name' => $plugin_config['name'], 'channel' => $active_plugin->plugin_path, 'options' => $channel_config);
         }
     }
     return self::$channels;
 }