/** * Set controller, action, [parameter, app_dir] for future calls to dispatch(). * @see dispatch * @access public * @return null */ function setParams() { // since we got this far, we need to rewrite $_SERVER['PHP_SELF'] to a pared down $_SERVER['REQUEST_URI'] $query_string = array_key_exists('QUERY_STRING', $_SERVER) ? $_SERVER['QUERY_STRING'] : ''; $_SERVER['PHP_SELF'] = str_replace('?' . $query_string, '', $_SERVER['REQUEST_URI']); NDebug::debug('' . $_SERVER['REMOTE_ADDR'] . ' requested ' . $_SERVER['PHP_SELF'], N_DEBUGTYPE_PAGE); // normalize the url $url = $this->url; $url = preg_replace("|index\\..*\$|i", "", $url); $url = preg_replace("|\\." . DEFAULT_PAGE_EXTENSION . "\$|i", "", $url); $url = preg_replace("|/\$|", "", $url); $url = preg_replace('|^/|', '', $url); // explode into an array $parts = explode('/', $url); // check if it's an nterchange specific controller if (isset($parts[0]) && $parts[0] == APP_DIR) { $this->app_dir = true; $app = array_shift($parts); if (empty($parts)) { $loc = '/' . APP_DIR . '/dashboard'; $qs = ''; foreach ($_GET as $k => $v) { $qs .= ($qs ? '&' : '?') . $k . '=' . urlencode($v); } $loc .= $qs; header('Location:' . $loc); exit; } } // set the controller, method and parameter and invoke $this->controller = isset($parts[0]) ? $parts[0] : null; $this->action = isset($parts[1]) ? $parts[1] : null; $this->parameter = isset($parts[2]) ? $parts[2] : null; }
function login() { NDebug::debug('Redirecting ' . $_SERVER['REMOTE_ADDR'] . ' to login to nterchange.', N_DEBUGTYPE_AUTH); $auth = new NAuth(); $auth->start(); $username = $auth->username; $status = $auth->status; $form = new NQuickForm('login_form', 'post', preg_replace('/logout=1[\\&]?/', '', $_SERVER['REQUEST_URI'])); $form->setDefaults(array('username' => $username)); if (isset($_GET['logout']) && $_GET['logout'] == 1) { $form->addElement('cmsalert', 'logout_header', 'You have signed out. Sign back in to continue.'); } else { if ($status < 0 && !empty($username)) { $form->addElement('cmserror', 'login_status', $auth->statusMessage($status)); } else { $form->addElement('cmsalert', 'login_status', 'Please sign in and you will be sent right along.'); } } $form->addElement('text', 'username', 'Username', array('maxlength' => 32, 'style' => 'width:300px;')); $form->addElement('password', 'password', 'Password', array('maxlength' => 32, 'style' => 'width:150px;')); // $form->addElement('checkbox', 'remember', null, 'Remember me for 2 weeks.'); $form->addElement('submit', 'login', 'Sign In'); $referer = isset($_GET['_referer']) ? urlencode($_GET['_referer']) : urlencode('/' . $this->base_dir); $form->addElement('hidden', '_referer', $referer); if ($auth->checkAuth()) { NDebug::debug('Logged ' . $_POST['username'] . ' from ' . $_SERVER['REMOTE_ADDR'] . ' in to nterchange.', N_DEBUGTYPE_AUTH); // Log this in the audit trail. $user_id = $auth->currentUserID(); $audit_trail =& NController::factory('audit_trail'); $audit_trail->insert(array('asset' => 'users', 'asset_id' => $user_id, 'action_taken' => AUDIT_ACTION_LOGIN)); unset($audit_trail); // Redirect to the page requested. header('Location:' . urldecode($referer)); exit; } $content = $form->toHTML(); $this->set(array('MAIN_CONTENT' => $content, 'username' => $username, 'status' => $status)); $this->auto_render = false; $this->render(array('layout' => 'login')); }
function page($parameter) { $page_id = $parameter; $this->_auth = new NAuth(); $this->auto_render = false; // set up the search form include_once 'n_quickform.php'; // search for the date /* @var $model cmsAuditTrail */ $model =& $this->getDefaultModel(); $model->page_id = $page_id; if ($model->find(array('order_by' => 'cms_created DESC'))) { $html = ''; while ($model->fetch()) { // Actually turn the id's into something readable. $info = $this->humanizeAuditTrailRecord($model); $this->set($info); $html .= $this->render(array('action' => 'page_audit_trail_record', 'return' => true)); } $this->set('audit_trail', $html); $this->set('result_count', $model->numRows()); } else { $this->set('result_count', 'no'); $this->set('audit_trail', '<p>There were no results found for the specified page.</p>'); } // Exposes an RSS feed link to Admin or higher users. if (defined('RSS_AUDIT_TRAIL') && RSS_AUDIT_TRAIL) { NDebug::debug('We are checking to see if we can display the RSS feed.', N_DEBUGTYPE_INFO); $this->checkRSSFeed(); } $this->loadSubnav($parameter); $this->render(array('layout' => 'default')); }
/** * deleteEverything - Delete all old versions of everything. Used just before * website launch or when somebody just wants to clean up. * NOTE: Not linked to from anywhere or really heavily tested. Use with caution. * * @return void **/ function deleteEverything($parameter) { if ($model =& $this->getDefaultModel()) { if ($model->find()) { while ($model->fetch()) { $arr = $model->toArray(); $content = unserialize($arr['version']); $success = $this->fileDelete($content, $arr['asset'], $arr['asset_id']); $this->deleteEmptyFolders($arr['asset'], $arr['asset_id']); $model->delete(); } // Let's empty out the entire table as well. $sql = 'TRUNCATE cms_nterchange_versions'; $db = NDB::connect(); $res = $db->query($sql); } else { NDebug::debug('There were no old versions of anything to delete.', N_DEBUGTYPE_INFO); } header('Location:/nterchange/'); } }
function deleteFile($filename) { if (!$this->connection || !$this->login_result) { $this->connect(); } // Take off the leading / $filename = eregi_replace('^/', '', $filename); // Change into MIRROR_REMOTE_DIR. ftp_chdir($this->connection, MIRROR_REMOTE_DIR); if (ftp_delete($this->connection, $filename)) { NDebug::debug("FTP Mirror: {$filename} WAS deleted successfully", N_DEBUGTYPE_INFO); } else { NDebug::debug("FTP Mirror: {$filename} was NOT deleted successfully", N_DEBUGTYPE_INFO); } }
function debug($message, $debug_type = N_DEBUGTYPE_INFO, $log_level = PEAR_LOG_DEBUG, $ident = false) { if (!$ident) { $ident = isset($this) && is_a($this, __CLASS__) ? get_class($this) : __CLASS__; } NDebug::debug($message, $debug_type, $log_level, $ident); }
/** * deleteSmartyCache - Delete the entire cache when you make a page change. * If you're including the navigation in the page as ul/li's - this keeps the * navigation always consistent. * * @return void **/ function deleteSmartyCache() { // Only delete the entire cache if the NAV_IN_PAGE is true and we're in production. if (defined('NAV_IN_PAGE') && NAV_IN_PAGE && ENVIRONMENT == 'production' && !isset($this->smarty_cache_cleared)) { NDebug::debug('We are clearing the smarty caches because of a page edit.', N_DEBUGTYPE_INFO); $view =& NView::singleton($this); $view->clear_all_cache(); $site_admin = NController::factory('site_admin'); $site_admin->rmDirFiles(CACHE_DIR . '/smarty_cache'); $site_admin->rmDirFiles(CACHE_DIR . '/templates_c'); $this->smarty_cache_cleared = true; } }
public static function debug($message, $t = N_DEBUGTYPE_INFO, $p = PEAR_LOG_DEBUG, $z = false) { NDebug::debug($message, $t, $p, $z); }
function removeJavascript($id = 0) { $page =& NController::singleton('page'); $page->base_view_dir = ROOT_DIR; $page->view_caching = (bool) PAGE_CACHING; $page->view_cache_lifetime = JS_CACHE_LIFETIME; $view_options = array('action' => 'blank'); // REMOVE JAVASCRIPT CACHES $javascript_caches = array('javascript', 'javascript_secure', 'javascript_qualified', 'admin_javascript', 'admin_edit_javascript'); foreach ($javascript_caches as $javascript_cache) { $page->view_cache_name = $javascript_cache; $view =& NView::singleton($page); $title = ucfirst(str_replace('_', ' ', $javascript_cache)); if ($view->isCached($view_options)) { $cache_cleared = $view->clearCache($view_options); if ($cache_cleared) { NDebug::debug($title . ' cache removed due to page edit on Page ID ' . $id . '.', N_DEBUGTYPE_CACHE); } else { NDebug::debug($title . ' cache failed attempted removal due to page edit on Page ID ' . $id . '.', N_DEBUGTYPE_CACHE); } } else { NDebug::debug($title . ' cache failed attempted removal due to page edit on Page ID ' . $id . ' but cache does not exist.', N_DEBUGTYPE_CACHE); } } unset($view); }
function deletePageCache($id) { if (!empty($id)) { // load the model $model =& NModel::singleton($this->name); $model->reset(); if ($model->get($id)) { $pk = $model->primaryKey(); // find the action $action = $this->getTemplate($model->page_template_id); $action = $action ? $action : 'default'; $action = $this->getTemplate($model->page_template_id); $action = $action ? $action : 'default'; // set up caching values $this->base_view_dir = ROOT_DIR; $this->view_caching = true; $this->view_cache_lifetime = $model->cache_lifetime; $this->view_cache_name = 'page' . $id; $view =& NView::singleton($this); if ($this->isCached($action)) { $cleared = $view->clearCache($action); $this->debug('Page cache for Page ID ' . $id . ($cleared ? ' removed' : ' failed attempted removal') . '.', N_DEBUGTYPE_CACHE); } else { $this->debug('Page cache for Page ID ' . $id . ' failed attempted removal since cache does not exist.', N_DEBUGTYPE_CACHE); } // Check the smarty_cache folder for additional caches from query string pages. $query_string_caches = CACHE_DIR . '/smarty_cache/page' . $id . '%*'; if (count(glob($query_string_caches)) != 0) { $files = glob($query_string_caches); foreach ($files as $file) { unlink($file); } NDebug::debug('Deleted query string cache files for page id ' . $id, N_DEBUGTYPE_INFO); } } unset($model); unset($view); } return; }
/** * deletePathRecursive - Deletes a file/folder and all it's contents * * @param string The file or folder to delete * @return boolean True if successfully deleted */ function deletePathRecursive($path) { $path = str_replace(DOCUMENT_ROOT, '', $path); $path = DOCUMENT_ROOT . $path; if (is_dir($path)) { if (substr($path, -1) != '/') { $path = $path . '/'; } $files = glob($path . '*', GLOB_MARK); $empty = true; foreach ($files as $file) { if (!self::deletePathRecursive($file)) { $empty = false; } } if ($empty) { return rmdir($path); } else { return false; } } if (is_file($path)) { return unlink($path); } // Not a file or a directory? NDebug::debug("Unable to remove: " . $path, N_DEBUGTYPE_INFO); return false; }
/** * dashboardVersionCheck - This runs for ADMIN users or higher and lets them know * if there is an upgrade available for nterchange. Called from the dashboard * helper and displays on the dashboard. * * @return void **/ function dashboardVersionCheck() { // Check the user level - this only shows up for admins or higher. $auth = new NAuth(); $current_user_level = $auth->getAuthData('user_level'); unset($auth); if ($current_user_level >= N_USER_ADMIN) { $newest = $this->versionCheck(); if (is_array($newest)) { $upgrade = $this->compareVersions(NTERCHANGE_VERSION, $newest['version']); if ($upgrade == true) { $this->set('upgrade', $newest); $this->set('nterchange_version', NTERCHANGE_VERSION); } else { $this->set('uptodate', true); } $this->render(array('action' => 'dashboard_version_check', 'return' => false)); } else { NDebug::debug('There was an error with the version check.', N_DEBUGTYPE_INFO); } } }