X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Faction.php;h=2a1e9ec8485e962caf0a62dded7e35e1ca0c0f9d;hb=2da928866b24417f8acb135e73d699e694b086df;hp=a914ff2b60bd021d3dd471a116fc3eb2b2c8e5d9;hpb=d36f0707a488b6e2513193a0a2f72811435553ec;p=quix0rs-gnu-social.git diff --git a/lib/action.php b/lib/action.php index a914ff2b60..2a1e9ec848 100644 --- a/lib/action.php +++ b/lib/action.php @@ -55,7 +55,21 @@ require_once INSTALLDIR.'/lib/htmloutputter.php'; */ class Action extends HTMLOutputter // lawsuit { - var $args; + // This should be protected/private in the future + public $args = array(); + + // Action properties, set per-class + protected $action = false; + protected $ajax = false; + protected $menus = true; + protected $needLogin = false; + + // The currently scoped profile + protected $scoped = null; + + // Messages to the front-end user + protected $error = null; + protected $msg = null; /** * Constructor @@ -73,6 +87,44 @@ class Action extends HTMLOutputter // lawsuit parent::__construct($output, $indent); } + function getError() + { + return $this->error; + } + + function getInfo() + { + return $this->msg; + } + + static public function run(array $args=array(), $output='php://output', $indent=null) { + $class = get_called_class(); + $action = new $class($output, $indent); + $action->execute($args); + return $action; + } + + public function execute(array $args=array()) { + // checkMirror stuff + if (common_config('db', 'mirror') && $this->isReadOnly($args)) { + if (is_array(common_config('db', 'mirror'))) { + // "load balancing", ha ha + $arr = common_config('db', 'mirror'); + $k = array_rand($arr); + $mirror = $arr[$k]; + } else { + $mirror = common_config('db', 'mirror'); + } + + // everyone else uses the mirror + common_config_set('db', 'database', $mirror); + } + + if ($this->prepare($args)) { + $this->handle($args); + } + } + /** * For initializing members of the class. * @@ -80,14 +132,23 @@ class Action extends HTMLOutputter // lawsuit * * @return boolean true */ - function prepare($argarray) + protected function prepare(array $args=array()) { - $this->args =& common_copy_args($argarray); + $this->args = common_copy_args($args); - if ($this->boolean('ajax')) { + $this->action = $this->trimmed('action'); + + if ($this->ajax || $this->boolean('ajax')) { + // check with StatusNet::isAjax() StatusNet::setAjax(true); } + if ($this->needLogin) { + $this->checkLogin(); // if not logged in, this redirs/excepts + } + + $this->scoped = Profile::current(); + return true; } @@ -165,7 +226,7 @@ class Action extends HTMLOutputter // lawsuit { $this->element('title', null, // TRANS: Page title. %1$s is the title, %2$s is the site name. - sprintf(_("%1\$s - %2\$s"), + sprintf(_('%1$s - %2$s'), $this->title(), common_config('site', 'name'))); } @@ -181,7 +242,7 @@ class Action extends HTMLOutputter // lawsuit function title() { // TRANS: Page title for a page without a title set. - return _("Untitled page"); + return _('Untitled page'); } /** @@ -229,7 +290,7 @@ class Action extends HTMLOutputter // lawsuit Event::handle('EndShowLaconicaStyles', array($this)); } - $this->cssLink(common_path('js/css/smoothness/jquery-ui.css')); + $this->cssLink(common_path('js/extlib/jquery-ui/css/smoothness/jquery-ui.css', StatusNet::isHTTPS())); if (Event::handle('StartShowUAStyles', array($this))) { $this->comment('[if IE]>comment('[if IE]>comment('[if IE]>viewdesigns) { - $design = $this->getDesign(); - - if (!empty($design)) { - $design->showCSS($this); - } - } - - Event::handle('EndShowDesign', array($this)); - } Event::handle('EndShowStyles', array($this)); if (common_config('custom_css', 'enabled')) { @@ -291,6 +340,13 @@ class Action extends HTMLOutputter // lawsuit $this->cssLink('css/display.css', $baseTheme, $media); } $this->cssLink('css/display.css', $mainTheme, $media); + + // Additional styles for RTL languages + if (is_rtl(common_language())) { + if (file_exists(Theme::file('css/rtl.css'))) { + $this->cssLink('css/rtl.css', $mainTheme, $media); + } + } } /** @@ -303,20 +359,23 @@ class Action extends HTMLOutputter // lawsuit if (Event::handle('StartShowScripts', array($this))) { if (Event::handle('StartShowJQueryScripts', array($this))) { if (common_config('site', 'minify')) { - $this->script('jquery.min.js'); + $this->script('extlib/jquery.min.js'); $this->script('jquery.form.min.js'); - $this->script('jquery-ui.min.js'); + $this->script('extlib/jquery-ui/jquery-ui.min.js'); $this->script('jquery.cookie.min.js'); - $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.min.js').'"); }'); + $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/extlib/json2.min.js', StatusNet::isHTTPS()).'"); }'); $this->script('jquery.joverlay.min.js'); + $this->script('jquery.infieldlabel.min.js'); } else { - $this->script('jquery.js'); + $this->script('extlib/jquery.js'); $this->script('jquery.form.js'); - $this->script('jquery-ui.min.js'); + $this->script('extlib/jquery-ui/jquery-ui.js'); $this->script('jquery.cookie.js'); - $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js').'"); }'); + $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/extlib/json2.js', StatusNet::isHTTPS()).'"); }'); $this->script('jquery.joverlay.js'); + $this->script('jquery.infieldlabel.js'); } + Event::handle('EndShowJQueryScripts', array($this)); } if (Event::handle('StartShowStatusNetScripts', array($this)) && @@ -328,9 +387,18 @@ class Action extends HTMLOutputter // lawsuit $this->script('xbImportNode.js'); $this->script('geometa.js'); } + // This route isn't available in single-user mode. + // Not sure why, but it causes errors here. + $this->inlineScript('var _peopletagAC = "' . + common_local_url('peopletagautocomplete') . '";'); $this->showScriptMessages(); - // Frame-busting code to avoid clickjacking attacks. - $this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }'); + // Anti-framing code to avoid clickjacking attacks in older browsers. + // This will show a blank page if the page is being framed, which is + // consistent with the behavior of the 'X-Frame-Options: SAMEORIGIN' + // header, which prevents framing in newer browser. + if (common_config('javascript', 'bustframes')) { + $this->inlineScript('if (window.top !== window.self) { document.write = ""; window.top.location = window.self.location; setTimeout(function () { document.body.innerHTML = ""; }, 1); window.self.onload = function () { document.body.innerHTML = ""; }; }'); + } Event::handle('EndShowStatusNetScripts', array($this)); Event::handle('EndShowLaconicaScripts', array($this)); } @@ -345,7 +413,6 @@ class Action extends HTMLOutputter // lawsuit * events and appending to the array. Try to avoid adding strings that won't be used, as * they'll be added to HTML output. */ - function showScriptMessages() { $messages = array(); @@ -539,7 +606,7 @@ class Action extends HTMLOutputter // lawsuit // if logo is an uploaded file, try to fall back to HTTPS file URL $httpUrl = common_config('site', 'logo'); if (!empty($httpUrl)) { - $f = File::staticGet('url', $httpUrl); + $f = File::getKV('url', $httpUrl); if (!empty($f) && !empty($f->filename)) { // this will handle the HTTPS case $logoUrl = File::url($f->filename); @@ -578,6 +645,14 @@ class Action extends HTMLOutputter // lawsuit function showPrimaryNav() { $this->elementStart('div', array('id' => 'site_nav_global_primary')); + + $user = common_current_user(); + + if (!empty($user) || !common_config('site', 'private')) { + $form = new SearchForm($this); + $form->show(); + } + $pn = new PrimaryNav($this); $pn->show(); $this->elementEnd('div'); @@ -609,17 +684,16 @@ class Action extends HTMLOutputter // lawsuit */ function showNoticeForm() { - $tabs = array('status' => _('Status')); + // TRANS: Tab on the notice form. + $tabs = array('status' => _m('TAB','Status')); $this->elementStart('div', 'input_forms'); if (Event::handle('StartShowEntryForms', array(&$tabs))) { - $this->elementStart('ul', array('class' => 'nav', 'id' => 'input_form_nav')); foreach ($tabs as $tag => $title) { - $attrs = array('id' => 'input_form_nav_'.$tag, 'class' => 'input_form_nav_tab'); @@ -647,7 +721,6 @@ class Action extends HTMLOutputter // lawsuit $this->elementEnd('div'); foreach ($tabs as $tag => $title) { - $attrs = array('class' => 'input_form', 'id' => 'input_form_'.$tag); @@ -657,7 +730,8 @@ class Action extends HTMLOutputter // lawsuit if (Event::handle('StartMakeEntryForm', array($tag, $this, &$form))) { if ($tag == 'status') { - $form = new NoticeForm($this); + $options = $this->noticeFormOptions(); + $form = new NoticeForm($this, $options); } Event::handle('EndMakeEntryForm', array($tag, $this, $form)); } @@ -673,6 +747,11 @@ class Action extends HTMLOutputter // lawsuit $this->elementEnd('div'); } + function noticeFormOptions() + { + return array(); + } + /** * Show anonymous message. * @@ -739,7 +818,6 @@ class Action extends HTMLOutputter // lawsuit * * @return nothing */ - function showProfileBlock() { if (common_logged_in()) { @@ -1145,11 +1223,9 @@ class Action extends HTMLOutputter // lawsuit /** * Handler method * - * @param array $argarray is ignored since it's now passed in in prepare() - * * @return boolean is read only action? */ - function handle($argarray=null) + protected function handle() { header('Vary: Accept-Encoding,Cookie'); @@ -1305,6 +1381,28 @@ class Action extends HTMLOutputter // lawsuit throw new ClientException($msg, $code); } + /** + * If not logged in, take appropriate action (redir or exception) + * + * @param boolean $redir Redirect to login if not logged in + * + * @return boolean true if logged in (never returns if not) + */ + public function checkLogin($redir=true) + { + if (common_logged_in()) { + return true; + } + + if ($redir==true) { + common_set_returnto($_SERVER['REQUEST_URI']); + common_redirect(common_local_url('login')); + } + + // TRANS: Error message displayed when trying to perform an action that requires a logged in user. + $this->clientError(_('Not logged in.'), 403); + } + /** * Returns the current URL * @@ -1349,16 +1447,26 @@ class Action extends HTMLOutputter // lawsuit * * @return nothing */ - function menuItem($url, $text, $title=null, $is_selected=false, $id=null) + function menuItem($url, $text, $title=null, $is_selected=false, $id=null, $class=null) { // Added @id to li for some control. // XXX: We might want to move this to htmloutputter.php - $lattrs = array(); + $lattrs = array(); + $classes = array(); + if ($class !== null) { + $classes[] = trim($class); + } if ($is_selected) { - $lattrs['class'] = 'current'; + $classes[] = 'current'; } - (is_null($id)) ? $lattrs : $lattrs['id'] = $id; + if (!empty($classes)) { + $lattrs['class'] = implode(' ', $classes); + } + + if (!is_null($id)) { + $lattrs['id'] = $id; + } $this->elementStart('li', $lattrs); $attrs['href'] = $url; @@ -1427,16 +1535,6 @@ class Action extends HTMLOutputter // lawsuit return null; } - /** - * A design for this action - * - * @return Design a design object to use - */ - function getDesign() - { - return Design::siteDesign(); - } - /** * Check the session token. *