public function __construct($args) { if (PerchUtil::count($args)) { $this->event = array_shift($args); $this->subject = array_shift($args); $this->args = $args; $Users = new PerchUsers(); $this->user = $Users->get_current_user(); } }
/** * Shift all users of this role over to the new role given. * * @param string $new_roleID * @return void * @author Drew McLellan */ public function migrate_users($new_roleID) { $Users = new PerchUsers(); $users = $Users->get_by_role($this->id()); $data = array(); $data['roleID'] = $new_roleID; if (PerchUtil::count($users)) { foreach ($users as $User) { $User->update($data); } } return true; }
public function __construct($args) { if (PerchUtil::count($args)) { $this->event = array_shift($args); $this->subject = array_shift($args); $this->args = $args; $Perch = Perch::fetch(); if ($Perch->admin) { $Users = new PerchUsers(); $this->user = $Users->get_current_user(); } else { $this->runtime = true; } } }
public function get_current_user() { if (!isset(self::$current_user)) { // use a plugin if it's there if (defined('PERCH_AUTH_PLUGIN') && PERCH_AUTH_PLUGIN) { $str = PERCH_AUTH_PLUGIN . '_auth_plugin'; if (!class_exists($str)) { require PERCH_PATH . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'auth' . DIRECTORY_SEPARATOR . PERCH_AUTH_PLUGIN . DIRECTORY_SEPARATOR . 'auth.php'; } $AuthenticatedUser = new $str(array()); } else { $AuthenticatedUser = new PerchAuthenticatedUser(array()); } $AuthenticatedUser->recover(); self::$current_user = $AuthenticatedUser; } return self::$current_user; }
} } if (PerchUtil::count($msgs)) { foreach ($msgs as $msg) { echo '<li class="failure icon"><strong>Error:</strong> ' . PerchUtil::html($msg) . '</li>'; } } if ($db_fail || PerchUtil::count($msgs)) { echo '<li class="failure icon">Creating database tables… <strong>Unable to create database tables.</strong></li>'; echo '</ul>'; echo '<p>The most likely cause is that your database access details aren\'t quite right. Please double check them. Note that some hosting control panel software (like cPanel) will prefix the database name with your account name. So if you created a new database called <code>' . PERCH_DB_DATABASE . '</code> the full name could be something like <code>accountname_' . PERCH_DB_DATABASE . '</code>.</p>'; echo '<p>If you\'re still have trouble, it\'s possible that the MySQL user hasn\'t got enough access rights to create tables. Change this, if you can, <a href="index.php?install=1">then reload this page</a>.</p>'; echo '<p>Still no success? <a href="https://grabaperch.com/support">Drop us a line</a> and we\'ll see if we can help.</p>'; } else { echo '<li class="success icon">Creating database tables… done.</li>'; $Users = new PerchUsers(); $data = PerchSession::get('user'); $data['userMasterAdmin'] = '1'; $data['roleID'] = '2'; $data['userCreated'] = date('Y-m-d H:i:s'); if ($Users->no_master_admin_exists()) { $Users->create($data, false); echo '<li class="success icon">Setting up initial user account… done.</li>'; } else { echo '<li class="success icon">Setting up initial user account… user already exists.</li>'; } ?> <li class="success icon"><strong>Setup complete.</strong></li> </ul> <h2>Next steps</h2>
PerchUtil::debug($User->msg, 'notice'); $error = 'weak_password'; } } else { $error = 'non_matching_passwords'; } } else { $error = 'non_matching_username'; } } } } if (isset($_POST['reset']) && $_POST['reset'] == '1' && isset($_POST['email']) && $_POST['email'] != '') { $email = $_POST['email']; if (PerchUtil::is_valid_email($email)) { $Users = new PerchUsers(); $User = $Users->find_by_email($email); if (is_object($User)) { $User->send_password_recovery_link(); } } $done = true; } include PERCH_CORE . '/inc/top.php'; ?> <div class="logincont <?php echo $Settings->get('headerScheme')->settingValue(); ?> "> <div class="logo"><a href="<?php echo PerchUtil::html(PERCH_LOGINPATH);
private function send_lockout_email($userID) { $Users = new PerchUsers(); $User = $Users->find((int) $userID); $User->send_lockout_email(); }
private function check_username($id, $args) { $str = $_POST[$id]; $Users = new PerchUsers(); // check for a passed in UserID // so that a user can be excluded from the check // (so we don't prevent editing of a record) if (isset($args['userID'])) { $exclude_userID = $args['userID']; } else { $exclude_userID = false; } if (!$Users->username_available($str, $exclude_userID)) { return false; } return true; }
public function receive_new_comment($SubmittedForm) { $input = $SubmittedForm->data; if ($input['parentID']) { $data = array(); $data['parentID'] = $input['parentID']; $data['commentDateTime'] = date('Y-m-d H:i:s'); foreach ($this->static_fields as $field) { if (!isset($data[$field])) { if (isset($input[$field]) && $input[$field] != '') { $data[$field] = trim($input[$field]); } } } // dynamic fields $dynamic_fields = array(); foreach ($input as $field => $val) { if (!isset($data[$field])) { $dynamic_fields[$field] = trim($val); } } $data['commentDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields); // Anti-spam $Settings = $this->api->get('Settings'); $akismetAPIKey = $Settings->get('perch_comments_akismet_key')->val(); $spam = false; $antispam = $SubmittedForm->get_antispam_values(); $environment = $_SERVER; $spam_data = array(); $spam_data['fields'] = $antispam; $spam_data['environment'] = $environment; $data['commentSpamData'] = PerchUtil::json_safe_encode($spam_data); $data['commentIP'] = ip2long($_SERVER['REMOTE_ADDR']); $spam = $this->_check_for_spam($antispam, $environment, $akismetAPIKey); if ($spam) { $data['commentStatus'] = 'SPAM'; } else { $Users = new PerchUsers(); $CurrentUser = $Users->get_current_user(); if (is_object($CurrentUser) && $CurrentUser->logged_in()) { $data['commentStatus'] = 'LIVE'; } else { $data['commentStatus'] = 'PENDING'; } } foreach ($data as $key => $val) { switch ($key) { case 'commentHTML': if (!class_exists('\\Netcarver\\Textile\\Parser', false) && class_exists('Textile', true)) { // sneaky autoloading hack } if (PERCH_HTML5) { $Textile = new \Netcarver\Textile\Parser('html5'); } else { $Textile = new \Netcarver\Textile\Parser(); } if (PERCH_RWD) { $val = $Textile->setDimensionlessImages(true)->textileRestricted($val); } else { $val = $Textile->textileRestricted($val); } if (defined('PERCH_XHTML_MARKUP') && PERCH_XHTML_MARKUP == false) { $val = str_replace(' />', '>', $val); } break; case 'commentURL': if (!parse_url($val, PHP_URL_SCHEME)) { $val = 'http://' . $val; } if (!parse_url($val, PHP_URL_SCHEME)) { $val = ''; } $val = strtolower($val); break; case 'commentEmail': $val = strtolower($val); break; case 'parentTitle': $val = html_entity_decode($val, ENT_QUOTES, 'UTF-8'); break; } $data[$key] = $val; } $r = $this->create($data); return $r; } PerchUtil::debug($SubmittedForm); }
<?php $Perch = Perch::fetch(); $Settings = PerchSettings::fetch(); $Users = new PerchUsers(); $CurrentUser = $Users->get_current_user(); ?> <div class="sidebar"> <ul class="metanav"> <?php if ($CurrentUser->has_priv('perch.settings')) { ?> <li> <a href="<?php echo PerchUtil::html(PERCH_LOGINPATH); ?> /core/settings/" class="icon settings<?php if ($Perch->get_section() == 'core/settings') { echo ' selected'; } ?> "><span><?php echo PerchLang::get('Settings'); ?> </span></a> </li> <?php } if (!defined('PERCH_AUTH_PLUGIN') || !PERCH_AUTH_PLUGIN) { ?> <li><a href="<?php
function perch_blog_check_preview() { if (!defined('PERCH_PREVIEW_ARG')) { define('PERCH_PREVIEW_ARG', 'preview'); } if (perch_get(PERCH_PREVIEW_ARG)) { $Users = new PerchUsers(); $CurrentUser = $Users->get_current_user(); if (is_object($CurrentUser) && $CurrentUser->logged_in()) { PerchUtil::debug('Entering preview mode'); PerchBlog_Posts::$preview_mode = true; } } }
/** * Duplicate all the region items with a new revision number * * @param string $regionID * @param string $old_rev * @param string $new_rev * @param boolean $copy_resources * @return void * @author Drew McLellan */ public function create_new_revision($regionID, $old_rev, $new_rev, $copy_resources = false) { $Users = new PerchUsers(); $CurrentUser = $Users->get_current_user(); $sql = 'INSERT INTO ' . $this->table . ' (itemID, regionID, pageID, itemRev, itemOrder, itemJSON, itemSearch, itemUpdatedBy) SELECT itemID, regionID, pageID, ' . $this->db->pdb($new_rev) . ' AS itemRev, itemOrder, itemJSON, itemSearch, ' . $this->db->pdb($CurrentUser->id()) . ' AS itemUpdatedBy FROM ' . $this->table . ' WHERE regionID=' . $this->db->pdb((int) $regionID) . ' AND itemRev=' . $this->db->pdb((int) $old_rev) . ' ORDER BY itemOrder ASC'; $this->db->execute($sql); if ($copy_resources) { $sql = 'REPLACE INTO ' . PERCH_DB_PREFIX . 'resource_log (appID, itemFK, itemRowID, resourceID) SELECT cr.appID, cr.itemFK, c2.itemRowID, cr.resourceID FROM ' . PERCH_DB_PREFIX . 'resource_log cr, ' . PERCH_DB_PREFIX . 'content_items c1, ' . PERCH_DB_PREFIX . 'content_items c2 WHERE cr.appID=' . $this->db->pdb('content') . ' AND cr.itemFK=' . $this->db->pdb('itemRowID') . ' AND cr.itemRowID=c1.itemRowID AND c1.itemID = c2.itemID AND c1.regionID=' . $this->db->pdb((int) $regionID) . ' AND c2.regionID=' . $this->db->pdb((int) $regionID) . ' AND c1.itemRev = ' . $this->db->pdb((int) $old_rev) . ' AND c2.itemRev = ' . $this->db->pdb((int) $new_rev); $this->db->execute($sql); } $this->renumber_items($regionID, $new_rev); }
function perch_content_check_preview() { if (!defined('PERCH_PREVIEW_ARG')) { define('PERCH_PREVIEW_ARG', 'preview'); } if (perch_get(PERCH_PREVIEW_ARG)) { $contentID = 'all'; $rev = false; $var = perch_get(PERCH_PREVIEW_ARG); if ($var != 'all' && $var != 'preview') { $rev = $var; if (strpos($rev, 'r')) { $parts = explode('r', $rev); $contentID = (int) $parts[0]; $rev = (int) $parts[1]; } } $Users = new PerchUsers(); $CurrentUser = $Users->get_current_user(); if (is_object($CurrentUser) && $CurrentUser->logged_in()) { $Content = PerchContent::fetch(); $Content->set_preview($contentID, $rev); } } }