Пример #1
0
 /**
  * Send request
  * 
  * @param string $request
  * 
  * @return stdClass|WP_Error
  * 
  * @access protected
  */
 protected static function send($request)
 {
     $response = AAM_Core_API::cURL($request, false);
     if (!is_wp_error($response)) {
         $response = json_decode($response['body']);
     }
     return $response;
 }
Пример #2
0
 /**
  * Main Frontend access control hook
  *
  * @return void
  *
  * @access public
  * @global WP_Query $wp_query
  * @global WP_Post $post
  */
 public function wp()
 {
     global $wp_query, $post;
     $user = AAM::getUser();
     if (!$wp_query->is_home() && $post instanceof WP_Post) {
         if ($user->getObject('post', $post->ID)->has('frontend.read')) {
             AAM_Core_API::reject();
         }
     }
 }
Пример #3
0
 /**
  * Main Frontend access control hook
  *
  * @return void
  *
  * @access public
  * @global WP_Post $post
  */
 public function wp()
 {
     global $post;
     $user = AAM::getUser();
     if (is_single() || is_page()) {
         if ($user->getObject('post', $post->ID)->has('frontend.read')) {
             AAM_Core_API::reject();
         }
     }
 }
Пример #4
0
 /**
  * Get list of user roles
  * 
  * @param array $roles
  * 
  * @return array
  * 
  * @access protected
  */
 protected function getUserRoles($roles)
 {
     $response = array();
     $names = AAM_Core_API::getRoles()->get_names();
     foreach ($roles as $role) {
         if (isset($names[$role])) {
             $response[] = translate_user_role($names[$role]);
         }
     }
     return $response;
 }
Пример #5
0
 /**
  * Main Frontend access control hook
  *
  * @return void
  *
  * @access public
  * @global WP_Post $post
  */
 public function wp()
 {
     global $post;
     $user = AAM::getUser();
     if (is_single() || is_page()) {
         $object = $user->getObject('post', $post->ID);
         if ($object->has('frontend.read')) {
             AAM_Core_API::reject();
         }
         //trigger any action that is listeting
         do_action('aam-wp-action', $object);
     }
 }
Пример #6
0
 /**
  * Prepare user row actions
  * 
  * @param WP_User $user
  * 
  * @return array
  * 
  * @access protected
  */
 protected function prepareRowActions(WP_User $user)
 {
     $max = AAM_Core_API::maxLevel(wp_get_current_user()->allcaps);
     if ($max < AAM_Core_API::maxLevel($user->allcaps)) {
         $actions = array('no-manage', 'no-lock', 'no-edit');
     } else {
         $actions = array('manage');
         $prefix = $user->ID == get_current_user_id() ? 'no-' : '';
         $actions[] = $prefix . ($user->user_status ? 'unlock' : 'lock');
         $actions[] = 'edit';
     }
     return $actions;
 }
Пример #7
0
 /**
  * Prepare user row actions
  * 
  * @param WP_User $user
  * 
  * @return array
  * 
  * @access protected
  */
 protected function prepareRowActions(WP_User $user)
 {
     $max = AAM_Core_API::maxLevel(wp_get_current_user()->allcaps);
     if ($max < AAM_Core_API::maxLevel($user->allcaps)) {
         $actions = array('no-manage', 'no-lock', 'no-edit');
     } else {
         $actions = array('manage');
         $prefix = $user->ID == get_current_user_id() ? 'no-' : '';
         $actions[] = $prefix . ($user->user_status ? 'unlock' : 'lock');
         $actions[] = 'edit';
     }
     if (class_exists('user_switching')) {
         $url = user_switching::maybe_switch_url($user);
         if (!in_array('edit', $actions) || empty($url)) {
             $actions[] = 'no-switch';
         } else {
             $actions[] = 'switch|' . $url;
         }
     }
     return $actions;
 }
Пример #8
0
 /**
  * Check extension status
  * 
  * The list of extensions is comming from the external server. This list is
  * updated daily by the registered cron-job.
  * Each extension is following by next naming convension and stardard - the 
  * title of an extension contains only latin letters and spaces and name is 
  * no longer than 50 characters. As a standard, each extension defines the 
  * global contant that indicates an extension version. The name of the 
  * contants derives from the extension title by transforming all letters to 
  * upper case and replacing the white spaces with underscore "_" 
  * (e.g AAM Plus Package defines the contant AAM_PLUS_PACKAGE). 
  * 
  * @param string $title
  * 
  * @return string
  * 
  * @access public
  */
 public function extensionStatus($title)
 {
     static $cache = null;
     $status = self::STATUS_INSTALLED;
     $const = str_replace(' ', '_', strtoupper($title));
     if (is_null($cache)) {
         $list = AAM_Core_API::getOption('aam-extension-list', array());
         $cache = array();
         foreach ($list as $row) {
             $cache[$row->title] = $row;
         }
     }
     if (!defined($const)) {
         //extension does not exist
         $status = self::STATUS_DOWNLOAD;
     } elseif (!empty($cache[$title])) {
         $version = constant($const);
         if ($version != $cache[$title]->version) {
             //version mismatch?
             $status = self::STATUS_UPDATE;
         }
     }
     return $status;
 }
Пример #9
0
 /**
  * 
  * @return type
  */
 public function getMetaboxList()
 {
     $cache = AAM_Core_API::getOption('aam_metabox_cache', array());
     $subject = AAM_Backend_View::getSubject();
     //if visitor, return only frontend widgets
     if ($subject instanceof AAM_Core_Subject_Visitor) {
         if (!empty($cache['widgets'])) {
             $response = array('widgets' => $cache['widgets']);
         } else {
             $response = array();
         }
     } else {
         $response = $cache;
     }
     return $response;
 }
Пример #10
0
 /**
  * Store the license key
  * 
  * This is important to have just for the update extension purposes
  * 
  * @param string $title
  * @param string $license
  * 
  * @return void
  * 
  * @access protected
  */
 protected function storeLicense($title, $license)
 {
     //retrieve the installed list of extensions
     $list = AAM_Core_API::getOption('aam-extension-license', array());
     $list[$title] = $license;
     //update the extension list
     AAM_Core_API::updateOption('aam-extension-license', $list);
 }
Пример #11
0
    /**
     * Add new capability
     * 
     * @return string
     * 
     * @access public
     */
    public function add() {
        $capability = trim(AAM_Core_Request::post('capability'));

        if ($capability) {
            //add the capability to administrator's role as default behavior
            AAM_Core_API::getRoles()->add_cap('administrator', $capability);
            $response = array('status' => 'success');
        } else {
            $response = array('status' => 'failure');
        }

        return json_encode($response);
    }
 /**
  * 
  * @return int
  */
 protected static function getNotification()
 {
     $list = AAM_Core_API::getOption('aam-extension-repository', array());
     $repo = AAM_Core_Repository::getInstance();
     $count = 0;
     foreach ($list as $extension) {
         $status = $repo->extensionStatus($extension->title);
         if ($status == AAM_Core_Repository::STATUS_UPDATE) {
             $count++;
         }
     }
     return $count;
 }
Пример #13
0
 /**
  *
  * @param type $object
  * @param type $object_id
  * @param type $default
  * @return type
  */
 public function readOption($object, $object_id = 0, $default = null)
 {
     return AAM_Core_API::getOption($this->getOptionName($object, $object_id), $default);
 }
Пример #14
0
 /**
  * 
  * @return type
  */
 protected function getCurrentSubject()
 {
     $userId = AAM_Core_Request::get('user');
     if ($userId) {
         $u = get_user_by('id', $userId);
         $subject = array('type' => 'user', 'id' => $userId, 'name' => $u->display_name ? $u->display_name : $u->user_nicename);
     } else {
         $roles = array_keys(get_editable_roles());
         $role = array_shift($roles);
         $subject = array('type' => 'role', 'id' => $role, 'name' => AAM_Core_API::getRoles()->get_role($role)->name);
     }
     return (object) $subject;
 }
Пример #15
0
 /**
  * Uninstall hook
  *
  * Remove all leftovers from AAM execution
  *
  * @return void
  *
  * @access public
  */
 public static function uninstall()
 {
     //trigger any uninstall hook that is registered by any extension
     do_action('aam-uninstall-action');
     //remove aam directory if exists
     $dirname = WP_CONTENT_DIR . '/aam';
     if (file_exists($dirname)) {
         AAM_Core_API::removeDirectory($dirname);
     }
     //clear schedules
     wp_clear_scheduled_hook('aam-cron');
 }
Пример #16
0
 /**
  *
  * @param type $object
  * @param type $id
  * @return type
  */
 public function readOption($object, $id = 0)
 {
     return AAM_Core_API::getOption($this->getOptionName($object, $id));
 }
Пример #17
0
 /**
  * Run daily routine
  * 
  * Check server extension versions
  * 
  * @return void
  * 
  * @access public
  */
 public static function cron()
 {
     //grab the server extension list
     $response = AAM_Core_Server::check();
     if (!is_wp_error($response)) {
         AAM_Core_API::updateOption('aam-extension-list', $response);
     }
 }
Пример #18
0
 /**
  * Control Edit Post
  *
  * Make sure that current user does not have access to edit Post
  *
  * @return void
  *
  * @access public
  */
 public function adminActionEdit()
 {
     global $post;
     if (is_a($post, 'WP_Post')) {
         $user = AAM::getUser();
         if ($user->getObject('post', $post->ID)->has('backend.edit')) {
             AAM_Core_API::reject();
         }
     }
 }
Пример #19
0
 /**
  * Clear cache
  * 
  * @param AAM_Core_Subject $subject
  * 
  * @return void
  * 
  * @access public
  */
 public function clearCache(AAM_Core_Subject $subject)
 {
     if ($this->isCacheOn()) {
         $group = $subject->getUID() . '-' . $subject->getId();
         if (isset($this->cache[$group])) {
             unset($this->cache[$group]);
         }
         AAM_Core_API::updateOption('aam-cache', $this->cache);
     }
 }
Пример #20
0
 /**
  * 
  * @return type
  */
 public function confirmWelcome()
 {
     return json_encode(array('status' => AAM_Core_API::updateOption('aam-welcome', 0)));
 }
 /**
  * 
  * @return type
  */
 protected function prepareExtensionCache()
 {
     if (empty($this->cache)) {
         $list = AAM_Core_API::getOption('aam-extension-repository', array());
         $licenses = AAM_Core_API::getOption('aam-extension-license', array());
         $this->cache = array();
         foreach ($list as $row) {
             $this->cache[$row->title] = $row;
             if (isset($licenses[$row->title])) {
                 $this->cache[$row->title]->license = $licenses[$row->title];
             }
         }
     }
     return $this->cache;
 }
Пример #22
0
 /**
  *
  * @param type $object
  * @param type $id
  * @return type
  */
 public function deleteOption($object, $id = 0)
 {
     return AAM_Core_API::deleteOption($this->getOptionName($object, $id));
 }
Пример #23
0
 /**
  * Print plugin localization
  * 
  * @param string $localKey
  * 
  * @return void
  * 
  * @access protected
  */
 protected function printLocalization($localKey)
 {
     $user = AAM_Core_Request::get('user');
     $roles = array_keys(get_editable_roles());
     $role = array_shift($roles);
     wp_localize_script($localKey, 'aamLocal', array('nonce' => wp_create_nonce('aam_ajax'), 'ajaxurl' => admin_url('admin-ajax.php'), 'url' => array('site' => admin_url('index.php'), 'jsbase' => AAM_MEDIA . '/js/aam', 'editUser' => admin_url('user-edit.php'), 'addUser' => admin_url('user-new.php')), 'subject' => array('type' => $user ? 'user' : 'role', 'id' => $user ? $user : $role, 'blog' => get_current_blog_id()), 'welcome' => AAM_Core_API::getOption('aam-welcome', 1)));
 }