diff --git a/Capfile b/Capfile new file mode 100644 index 00000000..f8a40843 --- /dev/null +++ b/Capfile @@ -0,0 +1,8 @@ +load 'deploy' if respond_to?(:namespace) # cap2 differentiator + +# Uncomment if you are using Rails' asset pipeline +# load 'deploy/assets' + +Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } + +load 'config/deploy' # remove this line to skip loading any of the default tasks \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 00000000..0ce39d4a --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,22 @@ +set :application, "set your application name here" +set :repository, "set your repository location here" + +set :scm, :subversion +# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` + +role :web, "your web-server here" # Your HTTP server, Apache/etc +role :app, "your app-server here" # This may be the same as your `Web` server +role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run +role :db, "your slave db-server here" + +# if you're still using the script/reaper helper you will need +# these http://github.com/rails/irs_process_scripts + +# If you are using Passenger mod_rails uncomment this: +# namespace :deploy do +# task :start do ; end +# task :stop do ; end +# task :restart, :roles => :app, :except => { :no_release => true } do +# run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" +# end +# end \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/action_jackson.php b/wordpress/wp-content/plugins/action_jackson/action_jackson.php new file mode 100755 index 00000000..415b6faf --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/action_jackson.php @@ -0,0 +1,115 @@ +getUserActions('posts', 'ID', $current_user->ID); + //$ajQuery->getUserActions('term', 'term_id', $current_user->ID, null, null, null, 'category'); + //$ajQuery->addUserAction(4, 'term', 'upvote', 'something', 1); + } + +// add_action('init', 'get_actions'); + + add_filter('posts_results', 'getUserActions'); + //add_filter('pre_get_posts', 'dont_suppress_filters'); + +function getUserActions($posts) { + global $current_user; + + $existingIds = array(); + $userId = (is_user_logged_in()) ? $current_user->ID : '1'; + + /** + * Check to see if there is anything in the $_GET + */ + $actionType = (isset($_GET['action']) && !empty($_GET['action'])) ? $_GET['action'] : null; + $page = (isset($_GET['paged']) && !empty($_GET['paged'])) ? $_GET['paged'] : 1; + + foreach($posts as $post) { + $ids[] = $post->ID; + + //$actions[] = new UserActionPost($post); + } +// public function getPostAction($object_type, $object_id, $post_action_id=null, $object_sub_type=null, $action_type=null, $limit=10, $page=1) { + $ajQuery = new ActionJacksonQuery(); + $postActions = $ajQuery->getPostAction('posts', $ids, null, null, null, null, null, false); + + $ids = array(); + + foreach($postActions as $postAction) { + $ids[] = $postAction->post_action_id; + + $actions[] = new PostAction($postAction); + } + + $userActions = $ajQuery->getUserActions($ids, $userId, $page, 10); + + foreach($userActions as $userAction) { + foreach($actions as $action) { + if($action->id == $userAction->object_id) { + $action->user = $userAction; + $action->user = new UserAction($userAction); + } + } + } + + foreach($posts as $post) { + foreach($actions as $action) { + if($action->objectId == $post->ID) { + $post->actions[] = $action; + } + } + } + + return $posts; +} + +function dont_suppress_filters($query){ + $query->query_vars['suppress_filters'] = false; + return $query; +} + +function addUserAction() { + $ajQuery = new ActionJacksonQuery(); + $result = $ajQuery->addUserAction((int)$_POST['id'], $_POST['type'], $_POST['userAction'], $_POST['subtype'], (int)$_POST['user']); + + echo json_encode($result); + exit; +} + +add_action('wp_ajax_add_user_action', 'addUserAction'); +add_action('wp_ajax_nopriv_add_user_action', 'addUserAction'); + + +function asdf($user) { + echo 'in asdf
'; + var_dump($user); + exit; +} + +add_filter('pre_user_query', 'asdf'); + diff --git a/wordpress/wp-content/plugins/action_jackson/base/action_jackson_admin.php b/wordpress/wp-content/plugins/action_jackson/base/action_jackson_admin.php new file mode 100644 index 00000000..6a1ec95d --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/base/action_jackson_admin.php @@ -0,0 +1,67 @@ +views = new FitStudioViewActions(); + + add_action('admin_menu', array(&$this, 'initializeSideMenu')); + add_action('admin_init', array(&$this, 'setOptions')); + } + + public function initializeSideMenu() { + add_options_page('UserActions', 'User Actions', 'manage_options', 'manage-fitstudio-hf', array(&$this, 'createForm')); + } + + public function createForm() { + $data = array('me' => 'sebastian'); + + $this->views->openView('form', $data); + } + + public function setOptions() { + register_setting('fitStudioOptions', 'fitStudioOptions-apiKey'); + register_setting('fitStudioOptions', 'fitStudioOptions-visibility'); + register_setting('fitStudioOptions', 'fitStudioOptions-apiUrl'); + register_setting('fitStudioOptions', 'fitStudioOptions-siteSection'); + + add_settings_section('infoSection', 'Use this plugin to turn on the header/footer for FitStudio', array(&$this,'printVisibility'), 'manage-fitstudio-hf'); + add_settings_field('apiUrl', '', array(&$this,'printApiUrl'), 'manage-fitstudio-hf', 'infoSection'); + add_settings_field('apiKey', '', array(&$this,'printApiKey'), 'manage-fitstudio-hf', 'infoSection'); + add_settings_field('toggleVisibility', '', array(&$this,'printVisibilityToggle'), 'manage-fitstudio-hf', 'infoSection'); + add_settings_field('siteSection', '', array(&$this,'printSiteSection'), 'manage-fitstudio-hf', 'infoSection'); + } + + public function getOption($name) { + return get_option($name); + } + + public function printVisibility() { + $this->views->openField(); + } + + public function printApiKey() { + $data = array('value' => $this->getOption('fitStudioOptions-apiKey')); + + $this->views->openField('fields/keys', $data); + } + + public function printVisibilityToggle() { + $data = array('value' => $this->getOption('fitStudioOptions-visibility')); + + $this->views->openField('fields/visibility', $data); + } + + public function printApiUrl() { + $data = array('value' => $this->getOption('fitStudioOptions-apiUrl')); + + $this->views->openField('fields/url', $data); + } + + public function printSiteSection() { + $data = array('value' => $this->getOption('fitStudioOptions-siteSection')); + + $this->views->openField('fields/section', $data); + } + } +?> \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/base/action_jackson_public.php b/wordpress/wp-content/plugins/action_jackson/base/action_jackson_public.php new file mode 100644 index 00000000..8455a1f3 --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/base/action_jackson_public.php @@ -0,0 +1,11 @@ +_wpdb = $wpdb; + + $this->_wpdb->tables = array_merge($this->_wpdb->tables, array($this->_wpdb->prefix.'post_action', $this->_wpdb->prefix.'user_actions')); + } + + public function addUserAction( + $objId, + $objType, + $action, + $objSubType=null, + $userId=1) { + if((int)$objId <= 0 || is_null($objId)) { + Throw new Exception('You need to pass an object ID!'); + } + + if((string)$objType === '' || is_null($objType)) { + Throw new Exception('You need to pass an object ID!'); + } + + $this->_getUserAction($userId, $action, $objId, $objType); + + $result = $this->_addPostAction($objId, $objType, $action, $objSubtype); + if(isset($result) && $result > 0) { + $args = array( + 'user_id' => $userId, + 'object_id' => $result, + 'action_added' => strtotime('now') + ); + + $result = $this->_wpdb->insert($this->_wpdb->prefix.'user_actions', $args); + + return $result; + } else { + return false; + } + } + + public function updateUserAction( + $actionId, + $objId=null, + $objType=null, + $objSubType=null, + $action=null) { + $args = array( + 'action_type' => $action, + 'object_type' => $objType, + 'object_subtype' => $objSubType, + 'object_id' => $objId + ); + + //$this->update( $table, $data, $where, $format = null, $where_format = null ); + $result = $this->_wpdb->update($this->_wpdb->prefix.'user_actions', $args, array('user_action_id' => $actionId)); + if($result == true) { + $this->_updatePostAction($actionId, $objId, $objType, $objSubType, $action); + } + } + + public function getUserActions($object_id, $user_id, $page=1, $limit=10) { + if( + ((isset($objId) && is_int($objId) && $objId > 0 ) && (!isset($objType) || is_null($objType) || $objType == '')) + || + ((!isset($objId) ||!is_int($objId) || $objId <= 0) && (isset($objType) && is_string($objType) && $objType != '')) + ) { + Throw new Exception('If you want to get a user\'s action based an object, you need to pass in an object type and object ID!'); + } + + /** + * This must be here, otherwise other non-argument variables will be included. + */ + $args = get_defined_vars(); + + unset($args['limit']); + unset($args['object_type_id_key_name']); + unset($args['page']); + unset($args['wp_query']); + + $startLimit = ($page * $limit) - $limit; + + $args = $this->_unsetNulls($args); + + $argCount = count($args); + + $query = 'SELECT + ua.* + FROM + '.$this->_wpdb->prefix.'user_actions ua + WHERE '; + + foreach($args as $key=>$arg) { + if(!is_null($arg) && !empty($arg)) { + $arg = is_string($arg) ? '"'.$arg.'"' : $arg; + + if(is_array($arg)) { + $query .= ($i < ($argCount - 1)) ? $key.' IN ('.implode(',', $arg).') AND ' : $key.' IN ('.implode(',', $arg).')'; + } else { + $query .= ($i < ($argCount - 1)) ? $key.'='.$arg.' AND ' : $key.'='.$arg; + } + + $i++; + } + } + + $query .= ' LIMIT '.$startLimit.','.$limit; + + return $this->_wpdb->get_results($query); + } + + public function getPostAction($object_type, $object_id, $object_sub_type=null, $post_action_id=null, $action_type=null, $limit=10, $page=1, $limited=true) { + $args = get_defined_vars(); + + unset($args['limit']); + unset($args['limited']); + unset($args['object_type_id_key_name']); + unset($args['page']); + unset($args['wp_query']); + + $startLimit = ($page * $limit) - $limit; + + $args = $this->_unsetNulls($args); + + $argCount = count($args); + + $query = 'SELECT + * + FROM + '.$this->_wpdb->prefix.'post_actions + WHERE '; + + foreach($args as $key=>$arg) { + if(!is_null($arg) && !empty($arg)) { + $arg = is_string($arg) ? '"'.$arg.'"' : $arg; + + if(is_array($arg)) { + $query .= ($i < ($argCount - 1)) ? $key.' IN ('.implode(',', $arg).') AND ' : $key.' IN ('.implode(',', $arg).')'; + } else { + $query .= ($i < ($argCount - 1)) ? $key.'='.$arg.' AND ' : $key.'='.$arg; + } + + $i++; + } + } + + $query .= $limited === true ? ' LIMIT '.$startLimit.','.$limit : ''; + + return $this->_wpdb->get_results($query); + } + + private function _addPostAction($objId, $objType, $action, $objectSubtype=null) { + $result = $this->getPostAction($objType, $objId, null, null, $action); + if(isset($result) && !empty($result)) { + $updated = $this->_updatePostAction($result[0]->post_action_id, null, null, null, $action, $result[0]->action_total); + if($updated == 1) { + return $result[0]->post_action_id; + } + } + + $args = array( + 'action_type' => $action, + 'object_type' => $objType, + 'object_subtype' => $objSubType, + 'object_id' => $objId, + 'action_total' => 1, + 'last_modified' => strtotime('now') + ); + + $result = $this->_wpdb->insert($this->_wpdb->prefix.'post_actions', $args); + if($result == 1) { + return $this->_wpdb->insert_id; + } + } + + private function _updatePostAction($actionId, $objId=null, $objType=null, $objSubType=null, $action=null, $action_total=null) { + $args = $this->_unsetNulls(array( + 'action_type' => $action, + 'object_type' => $objType, + 'object_subtype' => $objSubType, + 'object_id' => $objId, + 'action_total' => $action_total + 1 + )); + + $formats = $this->_buildFormats($args); + + return $this->_wpdb->update($this->_wpdb->prefix.'post_actions', $args, array('post_action_id' => $actionId), $formats, array('%d')); + } + + private function _getUserAction($user_action_id, $action_type, $object_id, $object_type) { + $args = get_defined_vars(); + + $query = 'SELECT + ua.*, pa.* + FROM + '.$this->_wpdb->prefix.'user_actions ua + JOIN + '.$this->_wpdb->prefix.'post_actions pa + ON + ua.object_id=pa.post_action_id + WHERE '; + + $args = $this->_unsetNulls($args); + + foreach($args as $key=>$arg) { + if(!is_null($arg) && !empty($arg)) { + $arg = is_string($arg) ? '"'.$arg.'"' : $arg; + + $tableAlias = ($key == 'user_id') ? 'ua' : 'pa'; + + $query .= ($i < ($argCount - 1)) ? $tableAlias.'.'.$key.'='.$arg.' AND ' : $tableAlias.'.'.$key.'='.$arg; + + $i++; + } + } + + echo $query; + exit; + + return $this->_wpdb->get_results($query); + } + + private function _unsetNulls($args) { + foreach($args as $key=>$arg) { + if(is_null($arg) || empty($arg)) { + unset($args[$key]); + } + } + + return $args; + } + + private function _buildFormats($args) { + $formats = array(); + + foreach($args as $key=>$arg) { + if(is_string($arg)) { + $formats[] = '%s'; + } elseif(is_int($arg)) { + $formats[] = '%d'; + } elseif(is_float($arg)) { + $formats[] = '%f'; + } + } + + return $formats; + } + } \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/base/action_jackson_views.php b/wordpress/wp-content/plugins/action_jackson/base/action_jackson_views.php new file mode 100644 index 00000000..56dbc0a4 --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/base/action_jackson_views.php @@ -0,0 +1,30 @@ +_open(FITSTUDIO_VIEWS_DIR.$view.'.view.php', $data); + } + } + + public function openField($field='', $data=null) { + if(isset($field) && !empty($field)) { + $this->_open(FITSTUDIO_VIEWS_DIR.$field.'.view.php', $data); + } + } + + private function _open($file, $data=null) { + if(file_exists($file)) { + if(is_array($data) && !empty($data)) { + // Make the data array available to the view. - Thanks, Brian Greenacre + extract($data, EXTR_SKIP); + } + + include($file); + } + } + } +?> \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/models/post_action.php b/wordpress/wp-content/plugins/action_jackson/models/post_action.php new file mode 100644 index 00000000..c194a36b --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/models/post_action.php @@ -0,0 +1,30 @@ +action = $postAction->action_type; + $this->id = (int)$postAction->post_action_id; + $this->lastModified = (int)$postAction->last_modified; + $this->objectId = (int)$postAction->object_id; + $this->objectType= $postAction->object_type; + $this->objectSubType = $postAction->object_subtype; + $this->total = (int)$postAction->action_total; + + $this->user = null; + } + } \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/models/user_action.php b/wordpress/wp-content/plugins/action_jackson/models/user_action.php new file mode 100644 index 00000000..fc642f7b --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/models/user_action.php @@ -0,0 +1,19 @@ +added = (int)$userAction->action_added; + $this->id = (int)$userAction->user_action_id; + $this->userId = (int)$userAction->user_id; + } + } \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/sql/wp_post_actions.sql b/wordpress/wp-content/plugins/action_jackson/sql/wp_post_actions.sql new file mode 100644 index 00000000..8dc14b20 --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/sql/wp_post_actions.sql @@ -0,0 +1,40 @@ +-- phpMyAdmin SQL Dump +-- version 3.4.0 +-- http://www.phpmyadmin.net +-- +-- Host: 127.0.0.1:3306 +-- Generation Time: May 28, 2012 at 12:42 PM +-- Server version: 5.5.14 +-- PHP Version: 5.3.8 + +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `communities` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `wp_post_actions` +-- + +CREATE TABLE IF NOT EXISTS `wp_post_actions` ( + `post_action_id` int(11) NOT NULL AUTO_INCREMENT, + `object_type` varchar(20) NOT NULL, + `object_id` int(11) NOT NULL, + `action_type` varchar(20) NOT NULL, + `action_total` int(11) NOT NULL, + PRIMARY KEY (`post_action_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/wordpress/wp-content/plugins/action_jackson/sql/wp_user_actions.sql b/wordpress/wp-content/plugins/action_jackson/sql/wp_user_actions.sql new file mode 100644 index 00000000..e87c1d6e --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/sql/wp_user_actions.sql @@ -0,0 +1,40 @@ +-- phpMyAdmin SQL Dump +-- version 3.4.0 +-- http://www.phpmyadmin.net +-- +-- Host: 127.0.0.1:3306 +-- Generation Time: May 28, 2012 at 12:42 PM +-- Server version: 5.5.14 +-- PHP Version: 5.3.8 + +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `communities` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `wp_user_actions` +-- + +CREATE TABLE IF NOT EXISTS `wp_user_actions` ( + `user_action_id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `action_type` varchar(20) NOT NULL, + `object_type` varchar(20) NOT NULL, + `object_id` int(11) NOT NULL, + PRIMARY KEY (`user_action_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/wordpress/wp-content/plugins/action_jackson/views/fields/keys.view.php b/wordpress/wp-content/plugins/action_jackson/views/fields/keys.view.php new file mode 100755 index 00000000..89e1b9fb --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/views/fields/keys.view.php @@ -0,0 +1,6 @@ +\ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/views/views/footer.view.php b/wordpress/wp-content/plugins/action_jackson/views/views/footer.view.php new file mode 100755 index 00000000..57790bb5 --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/views/views/footer.view.php @@ -0,0 +1,47 @@ ++ \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/views/fields/section.view.php b/wordpress/wp-content/plugins/action_jackson/views/fields/section.view.php new file mode 100755 index 00000000..0dbcbf50 --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/views/fields/section.view.php @@ -0,0 +1,6 @@ +API Key ++ + ++ \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/views/fields/url.view.php b/wordpress/wp-content/plugins/action_jackson/views/fields/url.view.php new file mode 100755 index 00000000..8bf8dbf2 --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/views/fields/url.view.php @@ -0,0 +1,6 @@ +Additional Site Section +
(This value will be something like "blog" or "gear", which allows you to pull a header from a particular section of the fitstudio website. You can leave it blank to get a header with no tab selected)+ + ++ \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/views/fields/visibility.view.php b/wordpress/wp-content/plugins/action_jackson/views/fields/visibility.view.php new file mode 100755 index 00000000..9364f5e5 --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/views/fields/visibility.view.php @@ -0,0 +1,9 @@ +API Url (Please ensure this is in the http://www.mysite.com/ template) ++ + ++ \ No newline at end of file diff --git a/wordpress/wp-content/plugins/action_jackson/views/form.view.php b/wordpress/wp-content/plugins/action_jackson/views/form.view.php new file mode 100755 index 00000000..c636bd72 --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/views/form.view.php @@ -0,0 +1,16 @@ +Turn the header/footer on/off ++ + +++ ++FitStudio Header/Footer Options
+
+ + + + diff --git a/wordpress/wp-content/plugins/action_jackson/views/views/header.view.php b/wordpress/wp-content/plugins/action_jackson/views/views/header.view.php new file mode 100755 index 00000000..47c4626b --- /dev/null +++ b/wordpress/wp-content/plugins/action_jackson/views/views/header.view.php @@ -0,0 +1,130 @@ + + + + +