Beispiel #1
0
 /**
  * Look for a term and prints it
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function ViewTerm()
 {
     $term = jaws()->request->fetch('term', 'get');
     $term = Jaws_XSS::defilter($term);
     $model = $this->gadget->model->load('Term');
     $term = $model->GetTerm($term);
     if (!Jaws_Error::IsError($term) && isset($term['term'])) {
         $this->SetTitle($term['term']);
         $tpl = $this->gadget->template->load('ViewTerm.html');
         $tpl->SetBlock('definition');
         $tpl->SetVariable('title', $this->gadget->title);
         $date = Jaws_Date::getInstance();
         $tpl->SetBlock('definition/term');
         $tpl->SetVariable('term', $term['term']);
         $tid = empty($term['fast_url']) ? $term['id'] : $term['fast_url'];
         $tpl->SetVariable('url', $this->gadget->urlMap('ViewTerm', array('term' => $tid)));
         $tpl->SetVariable('description', $this->gadget->ParseText($term['description']));
         $tpl->SetVariable('created_in', _t('GLOBAL_CREATETIME'));
         $tpl->SetVariable('updated_in', _t('GLOBAL_UPDATETIME'));
         $tpl->SetVariable('createtime', $date->Format($term['createtime']));
         $tpl->SetVariable('updatetime', $date->Format($term['updatetime']));
         $tpl->ParseBlock('definition/term');
         $tpl->ParseBlock('definition');
     } else {
         return Jaws_HTTPError::Get(404);
     }
     return $tpl->Get();
 }
Beispiel #2
0
 /**
  * Builds the NoPermission UI
  *
  * @access  public
  * @param   string  $user    Username
  * @param   string  $gadget  The Gadget user is requesting
  * @param   string  $action  The 'denied' action
  * @return  string  XHTML content
  */
 function ShowNoPermission($user, $gadget, $action)
 {
     // Load the template
     $tpl = $this->gadget->template->load('NoPermission.html');
     $tpl->SetBlock('NoPermission');
     $tpl->SetVariable('nopermission', _t('USERS_NO_PERMISSION_TITLE'));
     $tpl->SetVariable('description', _t('USERS_NO_PERMISSION_DESC', $gadget, $action));
     $tpl->SetVariable('admin_script', BASE_SCRIPT);
     $tpl->SetVariable('site-name', $this->gadget->registry->fetch('site_name', 'Settings'));
     $tpl->SetVariable('site-slogan', $this->gadget->registry->fetch('site_slogan', 'Settings'));
     $tpl->SetVariable('BASE_URL', $GLOBALS['app']->GetSiteURL('/'));
     $tpl->SetVariable('.dir', _t('GLOBAL_LANG_DIRECTION') == 'rtl' ? '.rtl' : '');
     if ($GLOBALS['app']->Session->Logged()) {
         $tpl->SetBlock('NoPermission/known');
         $logoutLink = $this->gadget->urlMap('Logout');
         $referLink = empty($_SERVER['HTTP_REFERER']) ? $GLOBALS['app']->getSiteURL('/') : Jaws_XSS::filter($_SERVER['HTTP_REFERER']);
         $tpl->SetVariable('known_description', _t('USERS_NO_PERMISSION_KNOWN_DESC', $logoutLink, $referLink));
         $tpl->ParseBlock('NoPermission/known');
     } else {
         $tpl->SetBlock('NoPermission/anon');
         $loginLink = $this->gadget->urlMap('LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(false))));
         $referLink = empty($_SERVER['HTTP_REFERER']) ? $GLOBALS['app']->getSiteURL('/') : Jaws_XSS::filter($_SERVER['HTTP_REFERER']);
         $tpl->SetVariable('anon_description', _t('USERS_NO_PERMISSION_ANON_DESC', $loginLink, $referLink));
         $tpl->ParseBlock('NoPermission/anon');
     }
     $tpl->ParseBlock('NoPermission');
     return $tpl->Get();
 }
Beispiel #3
0
 /**
  * Creates and returns some data
  *
  * @access  public
  * @param   string  $dir
  * @param   int     $offset
  * @param   int     $order
  * @return  array   directory tree array
  */
 function GetDirectory($dir, $offset, $order)
 {
     $model = $this->gadget->model->load('Directory');
     $files = $model->ReadDir($dir, 15, $offset, $order);
     if (Jaws_Error::IsError($files)) {
         return array();
         //Jaws_Error::Fatal($files->getMessage(), __FILE__, __LINE__);
     }
     $tree = array();
     foreach ($files as $file) {
         $item = array();
         //Icon
         $link =& Piwi::CreateWidget('Image', $file['mini_icon']);
         $item['image'] = $link->Get();
         //Title
         $item['title'] = $file['title'];
         $actions = '';
         if ($file['is_dir']) {
             $link =& Piwi::CreateWidget('Link', $file['filename'], "javascript: cwd('{$file['relative']}');");
             $link->setStyle('float: left;');
             $item['name'] = $link->Get();
             if ($this->gadget->GetPermission('ManageDirectories')) {
                 //edit directory properties
                 $link =& Piwi::CreateWidget('Link', _t('GLOBAL_EDIT'), "javascript: editDir(this, '{$file['filename']}');", STOCK_EDIT);
                 $actions .= $link->Get() . ' ';
                 //delete directory
                 $link =& Piwi::CreateWidget('Link', _t('GLOBAL_DELETE'), "javascript: delDir(this, '{$file['filename']}');", STOCK_DELETE);
                 $actions .= $link->Get() . ' ';
             }
         } else {
             if (empty($file['id'])) {
                 $furl = Jaws_XSS::filter($file['url']);
             } else {
                 $fid = empty($file['fast_url']) ? $file['id'] : Jaws_XSS::filter($file['fast_url']);
                 $furl = $this->gadget->urlMap('Download', array('id' => $fid));
             }
             $link =& Piwi::CreateWidget('Link', $file['filename'], $furl);
             $link->setStyle('float: left;');
             $item['name'] = $link->Get();
             if ($this->gadget->GetPermission('ManageFiles')) {
                 //edit file properties
                 $link =& Piwi::CreateWidget('Link', _t('GLOBAL_EDIT'), "javascript: editFile(this, '{$file['filename']}');", STOCK_EDIT);
                 $actions .= $link->Get() . ' ';
                 //delete file
                 $link =& Piwi::CreateWidget('Link', _t('GLOBAL_DELETE'), "javascript: delFile(this, '{$file['filename']}');", STOCK_DELETE);
                 $actions .= $link->Get() . ' ';
             }
         }
         $item['size'] = $file['size'];
         $item['hits'] = $file['hits'];
         $item['actions'] = $actions;
         $tree[] = $item;
     }
     return $tree;
 }
Beispiel #4
0
 /**
  * Checks the Agent is blocked or not
  *
  * @access  public
  * @param   string  $agent  Agent
  * @return  bool    True if the Agent is blocked
  */
 function IsAgentBlocked($agent)
 {
     $table = Jaws_ORM::getInstance()->table('policy_agentblock');
     $table->select('blocked:boolean');
     $table->where('agent', Jaws_XSS::filter($agent));
     $blocked = $table->fetchOne();
     if (!Jaws_Error::IsError($blocked) && !is_null($blocked)) {
         return $blocked;
     }
     return $this->gadget->registry->fetch('block_undefined_agent') == 'true';
 }
Beispiel #5
0
 /**
  * Displays an Atom feed for a given blog category
  *
  * @access  public
  * @return  string  xml with Atom feed
  */
 function ShowAtomCategory()
 {
     header('Content-type: application/atom+xml; charset=utf-8');
     $id = jaws()->request->fetch('id', 'get');
     $id = Jaws_XSS::defilter($id);
     $model = $this->gadget->model->load('Feeds');
     $xml = $model->MakeCategoryAtom($id);
     if (Jaws_Error::IsError($xml)) {
         return '';
     }
     return $xml;
 }
Beispiel #6
0
 /**
  * Displays a block of pages belongs to the specified group
  *
  * @access  public
  * @param   mixed   $gid    ID or fast_url of the group (int/string)
  * @param   int     $orderBy
  * @param   int     $limit    limit show pages
  * @return  string  XHTML content
  */
 function GroupPages($gid = 0, $orderBy = 1, $limit = 0)
 {
     if (empty($gid)) {
         $get = $this->gadget->request->fetch(array('gid', 'order'), 'get');
         $gid = Jaws_XSS::defilter($get['gid']);
         $orderBy = $get['order'];
     }
     $pModel = $this->gadget->model->load('Page');
     $gModel = $this->gadget->model->load('Group');
     $group = $gModel->GetGroup($gid);
     if (Jaws_Error::IsError($group) || $group == null) {
         return false;
     }
     if (!$this->gadget->GetPermission('AccessGroup', $group['id'])) {
         return Jaws_HTTPError::Get(403);
     }
     $GLOBALS['app']->Layout->SetTitle($group['title']);
     $GLOBALS['app']->Layout->AddToMetaKeywords($group['meta_keywords']);
     $GLOBALS['app']->Layout->SetDescription($group['meta_description']);
     if (!is_numeric($gid)) {
         $gid = $group['id'];
     }
     $pages = $pModel->GetPages($gid, $limit, $orderBy, null, true);
     if (Jaws_Error::IsError($pages)) {
         return false;
     }
     $tpl = $this->gadget->template->load('StaticPage.html');
     $tpl->SetBlock('group_pages');
     $tpl->SetVariable('title', $group['title']);
     foreach ($pages as $page) {
         $param = array('gid' => empty($group['fast_url']) ? $group['id'] : $group['fast_url'], 'pid' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url']);
         $link = $this->gadget->urlMap('Pages', $param);
         $tpl->SetBlock('group_pages/item');
         $tpl->SetVariable('page', $page['title']);
         $tpl->SetVariable('link', $link);
         $tpl->ParseBlock('group_pages/item');
     }
     // parsing read-more block if required
     if (!empty($limit) && count($pages) >= $limit && $GLOBALS['app']->requestedActionMode == ACTION_MODE_LAYOUT) {
         $urlParam = array('gid' => empty($group['fast_url']) ? $group['id'] : $group['fast_url'], 'order' => $orderBy);
         // prevent duplicate content via two different url
         if ($orderBy == 1) {
             unset($urlParam['order']);
         }
         $tpl->SetBlock('group_pages/read-more');
         $tpl->SetVariable('url', $this->gadget->urlMap('GroupPages', $urlParam));
         $tpl->SetVariable('read_more', _t('STATICPAGE_GROUP_PAGES_LIST', $group['title']));
         $tpl->ParseBlock('group_pages/read-more');
     }
     $tpl->ParseBlock('group_pages');
     return $tpl->Get();
 }
Beispiel #7
0
 /**
  * Updates the emblem
  *
  * @access  public
  * @return  array   Response array (notice or error)
  */
 function UpdateEmblem()
 {
     @(list($id, $data) = jaws()->request->fetch(array('0', '1:array'), 'post'));
     $data['url'] = Jaws_XSS::defilter($data['url']);
     $model = $this->gadget->model->loadAdmin('Emblems');
     $res = $model->UpdateEmblem($id, $data);
     if (Jaws_Error::IsError($res)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR);
         return new Jaws_Error($res->getMessage());
     }
     $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_UPDATED'), RESPONSE_NOTICE);
     return $GLOBALS['app']->Session->PopLastResponse();
 }
Beispiel #8
0
 /**
  * Fetch WWW-Authentication data
  *
  * @access  public
  * @return  void
  */
 function AssignData()
 {
     if (!empty($_SERVER['PHP_AUTH_USER'])) {
         $this->username = Jaws_XSS::filter($_SERVER['PHP_AUTH_USER']);
     }
     if (!empty($_SERVER['PHP_AUTH_PW'])) {
         $this->password = Jaws_XSS::filter($_SERVER['PHP_AUTH_PW']);
     }
     //Try to get authentication information from IIS
     if (empty($this->username) && empty($this->password) && !empty($_SERVER['HTTP_AUTHORIZATION'])) {
         list($this->username, $this->password) = explode(':', base64_decode(substr($this->server['HTTP_AUTHORIZATION'], 6)));
     }
 }
Beispiel #9
0
 /**
  * Create a new Friend
  *
  * @access  public
  * @param   string  $friend Friend name
  * @param   string  $url    Friend's url
  * @return  mixed   True if query is successful, if not, returns Jaws_Error on any error
  */
 function NewFriend($friend, $url)
 {
     $params['friend'] = Jaws_XSS::filter($friend);
     $params['url'] = Jaws_XSS::filter($url);
     $friendTable = Jaws_ORM::getInstance()->table('friend');
     $result = $friendTable->insert($params)->exec();
     if (Jaws_Error::IsError($result)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('FRIENDS_ERROR_NOT_ADDED'), RESPONSE_ERROR);
         return new Jaws_Error(_t('FRIENDS_ERROR_NOT_ADDED'));
     }
     $GLOBALS['app']->Session->PushLastResponse(_t('FRIENDS_ADDED'), RESPONSE_NOTICE);
     return true;
 }
Beispiel #10
0
 /**
  * Show links of the category
  *
  * @access  public
  * @return  mixed  XHTML template content or false on error
  */
 function Category($gid = 0)
 {
     if (empty($gid)) {
         $gid = $this->gadget->request->fetch('id', 'get');
         $gid = Jaws_XSS::defilter($gid);
         $limit_count = null;
         $tplFile = 'Category.html';
     } else {
         $limit_count = 10;
         $tplFile = 'LinkDump.html';
     }
     $model = $this->gadget->model->load('Groups');
     $group = $model->GetGroup($gid);
     if (Jaws_Error::IsError($group) || empty($group)) {
         return false;
     }
     $tpl = $this->gadget->template->load($tplFile);
     $tpl->SetBlock('category');
     $tpl->SetVariable('gid', $group['id']);
     $tpl->SetVariable('title', $this->gadget->title);
     $tpl->SetVariable('name', $group['title']);
     $tpl->SetVariable('feed', _t('LINKDUMP_LINKS_FEED'));
     $gid = empty($group['fast_url']) ? $group['id'] : $group['fast_url'];
     $tpl->SetVariable('url_category', $this->gadget->urlMap('Category', array('id' => $gid)));
     $group_id = empty($group['fast_url']) ? $group['id'] : $group['fast_url'];
     $tpl->SetVariable('linkdump_rss', $this->gadget->urlMap('RSS', array('id' => $group_id)));
     $target = $this->gadget->registry->fetch('links_target');
     $target = $target == 'blank' ? '_blank' : '_self';
     $block = $group['link_type'] == 0 ? 'list' : 'link';
     $links = $model->GetGroupLinks($group['id'], empty($limit_count) ? null : $group['limit_count'], $group['order_type']);
     if (!Jaws_Error::IsError($links)) {
         foreach ($links as $link) {
             $tpl->SetBlock("category/{$block}");
             $tpl->SetVariable('target', $target);
             $tpl->SetVariable('title', $link['title']);
             $tpl->SetVariable('description', $link['description']);
             $tpl->SetVariable('url', $link['url']);
             $tpl->SetVariable('clicks', $link['clicks']);
             $tpl->SetVariable('lbl_clicks', _t('LINKDUMP_LINKS_CLICKS'));
             if ($group['link_type'] == 2) {
                 $lid = empty($link['fast_url']) ? $link['id'] : $link['fast_url'];
                 $tpl->SetVariable('visit_url', $this->gadget->urlMap('Link', array('id' => $lid)));
             } else {
                 $tpl->SetVariable('visit_url', $link['url']);
             }
             $tpl->ParseBlock("category/{$block}");
         }
     }
     $tpl->ParseBlock('category');
     return $tpl->Get();
 }
Beispiel #11
0
 /**
  * Inserts a Log
  *
  * @access  public
  * @param   string  $gadget     Gadget name
  * @param   string  $action     Action name
  * @param   int     $priority   Priority of log
  * @param   array   $params     Action parameters
  * @param   int     $status     Status code
  * @return  mixed   Log identity or Jaws_Error on failure
  */
 function InsertLog($user, $gadget, $action, $priority = 0, $params = null, $status = 200)
 {
     // ip address
     $ip = 0;
     if (preg_match('/\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b/', $_SERVER['REMOTE_ADDR'])) {
         $ip = ip2long($_SERVER['REMOTE_ADDR']);
         $ip = $ip < 0 ? $ip + 0xffffffff + 1 : $ip;
     }
     // agent
     $agent = substr(Jaws_XSS::filter($_SERVER['HTTP_USER_AGENT']), 0, 252);
     $logsTable = Jaws_ORM::getInstance()->table('logs');
     $logsTable->insert(array('user' => (int) $user, 'gadget' => $gadget, 'action' => $action, 'priority' => $priority, 'params' => $params, 'apptype' => JAWS_APPTYPE, 'backend' => JAWS_SCRIPT == 'admin', 'ip' => $ip, 'agent' => $agent, 'status' => (int) $status, 'insert_time' => time()));
     return $logsTable->exec();
 }
Beispiel #12
0
 /**
  * Displays a concrete category
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function ViewCategory()
 {
     $model = $this->gadget->model->load('Question');
     $cat_id = jaws()->request->fetch('id', 'get');
     $cat_id = Jaws_XSS::defilter($cat_id);
     $this->SetTitle($this->gadget->title . ' - ' . _t('FAQ_CATEGORIES'));
     $questions = $model->GetQuestions($cat_id, true);
     if (is_array($questions) && count($questions) > 0) {
         $tpl = $this->gadget->template->load('Category.html');
         foreach ($questions as $cat) {
             $tpl->SetBlock('faq_category');
             $tpl->SetVariable('title', _t('FAQ_TITLE'));
             $tpl->SetVariable('category', $cat['category']);
             $tpl->SetVariable('description', $this->gadget->ParseText($cat['description']));
             if (isset($cat['questions']) && is_array($cat['questions'])) {
                 $qPos = 0;
             }
             foreach ($cat['questions'] as $q) {
                 $qPos++;
                 $tpl->SetBlock('faq_category/question');
                 $tpl->SetVariable('id', $q['id']);
                 $tpl->SetVariable('pos', $qPos);
                 $tpl->SetVariable('question', $q['question'], 'Faq', false);
                 $tpl->SetVariable('url', $this->gadget->urlMap('ViewCategory', array('id' => $cat_id)));
                 $tpl->ParseBlock('faq_category/question');
             }
             if (isset($cat['questions']) && is_array($cat['questions'])) {
                 $qPos = 0;
             }
             foreach ($cat['questions'] as $q) {
                 $qPos++;
                 $tpl->SetBlock('faq_category/item');
                 $tpl->SetVariable('top_label', _t('FAQ_GO_TO_TOP'));
                 $tpl->SetVariable('top_link', $this->gadget->urlMap('ViewCategory', array('id' => $cat_id)) . '#topfaq');
                 $tpl->SetVariable('id', $q['id']);
                 $tpl->SetVariable('pos', $qPos);
                 $qid = empty($q['fast_url']) ? $q['id'] : $q['fast_url'];
                 $tpl->SetVariable('url', $this->gadget->urlMap('ViewQuestion', array('id' => $qid)));
                 $tpl->SetVariable('question', $q['question']);
                 $tpl->SetVariable('answer', $this->gadget->ParseText($q['answer']));
                 $tpl->ParseBlock('faq_category/item');
             }
             $tpl->ParseBlock('faq_category');
         }
         return $tpl->Get();
     }
     // FIXME: We should return something like "No questions found"
     return '';
 }
Beispiel #13
0
 /**
  * Builds the advanced search box
  *
  * @access  public
  * @return  string  XHTML search box
  */
 function AdvancedBox()
 {
     $post = jaws()->request->fetch(array('all', 'exact', 'least', 'exclude', 'gadgets', 'date'), 'get');
     $post['all'] = Jaws_XSS::defilter($post['all']);
     $tpl = $this->gadget->template->load('Search.html');
     $tpl->SetBlock('AdvancedBox');
     $tpl->SetVariable('base_script', BASE_SCRIPT);
     $tpl->SetVariable('title', $this->gadget->title);
     $tpl->SetVariable('lbl_word_filter', _t('SEARCH_WORD_FILTER'));
     $tpl->SetVariable('lbl_all', _t('SEARCH_WORD_FILTER_ALL'));
     $tpl->SetVariable('lbl_exact', _t('SEARCH_WORD_FILTER_EXACT'));
     $tpl->SetVariable('lbl_least', _t('SEARCH_WORD_FILTER_LEAST'));
     $tpl->SetVariable('lbl_exclude', _t('SEARCH_WORD_FILTER_EXCLUDE'));
     $tpl->SetVariable('lbl_data_filter', _t('SEARCH_DATA_FILTER'));
     $tpl->SetVariable('lbl_search_in', _t('SEARCH_SEARCH_IN'));
     $model = $this->gadget->model->load('Search');
     $options = $model->parseSearch($post, $searchable);
     $wordAll =& Piwi::CreateWidget('Entry', 'all', implode(' ', $options['all']));
     $wordExact =& Piwi::CreateWidget('Entry', 'exact', implode(' ', $options['exact']));
     $wordLeast =& Piwi::CreateWidget('Entry', 'least', implode(' ', $options['least']));
     $wordExclude =& Piwi::CreateWidget('Entry', 'exclude', implode(' ', $options['exclude']));
     $tpl->SetVariable('all', $wordAll->Get());
     $tpl->SetVariable('exclude', $wordExclude->Get());
     $tpl->SetVariable('least', $wordLeast->Get());
     $tpl->SetVariable('exact', $wordExact->Get());
     //Gadgets filter combo
     $gadgetList = $model->GetSearchableGadgets();
     $gSearchable = $this->gadget->registry->fetch('searchable_gadgets');
     $searchableGadgets = $gSearchable == '*' ? array_keys($gadgetList) : explode(', ', $gSearchable);
     $gchk =& Piwi::CreateWidget('Combo', 'gadgets');
     $gchk->addOption(_t('GLOBAL_ALL'), '');
     foreach ($searchableGadgets as $gadget) {
         $info = Jaws_Gadget::getInstance($gadget);
         if (Jaws_Error::IsError($info)) {
             continue;
         }
         $gchk->AddOption($info->title, $gadget);
     }
     $default = !is_null($post['gadgets']) ? $post['gadgets'] : '';
     $gchk->SetDefault($default);
     $tpl->SetVariable('gadgets_combo', $gchk->Get());
     //Search button
     $btnSearch =& Piwi::CreateWidget('Button', '', _t('SEARCH_BUTTON'));
     $btnSearch->SetID('btn_search');
     $btnSearch->SetSubmit(true);
     $tpl->SetVariable('btn_search', $btnSearch->Get());
     $tpl->ParseBlock('AdvancedBox');
     return $tpl->Get();
 }
Beispiel #14
0
 /**
  * Redirect to the URL and increase the clicks by one
  * 
  * @access  public
  */
 function Link()
 {
     $lid = jaws()->request->fetch('id', 'get');
     $lid = Jaws_XSS::defilter($lid);
     $model = $this->gadget->model->load('Links');
     $link = $model->GetLink($lid);
     if (!Jaws_Error::IsError($link) && !empty($link)) {
         $click = $model->Click($link['id']);
         if (!Jaws_Error::IsError($click)) {
             Jaws_Header::Location($link['url'], null, 301);
         }
     }
     // By default, on the errors stay in the main page
     Jaws_Header::Referrer();
 }
Beispiel #15
0
 /**
  * Displays a concrete question & answer
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function ViewQuestion()
 {
     $qid = jaws()->request->fetch('id', 'get');
     $qid = Jaws_XSS::defilter($qid);
     $tpl = $this->gadget->template->load('Question.html');
     $tpl->SetBlock('faq_question');
     $model = $this->gadget->model->load('Question');
     $q = $model->GetQuestion($qid);
     if (!Jaws_Error::IsError($q) && !empty($q)) {
         $this->SetTitle($q['question']);
         $tpl->SetVariable('title', $q['question']);
         $tpl->SetVariable('answer', $this->gadget->ParseText($q['answer']));
     }
     $tpl->ParseBlock('faq_question');
     return $tpl->Get();
 }
Beispiel #16
0
 /**
  * Displays a list of blog posts included on the given category
  *
  * @access  public
  * @param   int     $cat    category ID
  * @return  string  XHTML template content
  */
 function ShowCategory($cat = null)
 {
     $cModel = $this->gadget->model->load('Categories');
     $pModel = $this->gadget->model->load('Posts');
     $rqst = jaws()->request->fetch(array('id', 'page'), 'get');
     $page = $rqst['page'];
     if (is_null($page) || $page <= 0) {
         $page = 1;
     }
     if (is_null($cat)) {
         if (empty($rqst['id'])) {
             $catInfo = array('id' => 0, 'name' => _t('BLOG_UNCATEGORIZED'), 'fast_url' => '', 'description' => '', 'meta_keywords' => '', 'meta_description' => '');
         } else {
             $cat = Jaws_XSS::defilter($rqst['id']);
             $catInfo = $cModel->GetCategory($cat);
             if (Jaws_Error::IsError($catInfo) || empty($catInfo)) {
                 return Jaws_HTTPError::Get(404);
             }
             // Check dynamic ACL
             if (!$this->gadget->GetPermission('CategoryAccess', $catInfo['id'])) {
                 return Jaws_HTTPError::Get(403);
             }
         }
     }
     $name = $catInfo['name'];
     $tpl = $this->gadget->template->load('CategoryPosts.html');
     $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('ShowAtomCategory', array('id' => $cat)), 'alternate', 'application/atom+xml', 'Atom - ' . $name);
     $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('ShowRSSCategory', array('id' => $cat)), 'alternate', 'application/rss+xml', 'RSS 2.0 - ' . $name);
     $this->SetTitle($name);
     $this->AddToMetaKeywords($catInfo['meta_keywords']);
     $this->SetDescription($catInfo['meta_description']);
     $tpl->SetBlock('view_category');
     $tpl->SetVariable('title', $name);
     $total = $cModel->GetCategoryNumberOfPages($catInfo['id']);
     $limit = $this->gadget->registry->fetch('last_entries_limit');
     $params = array('id' => $cat);
     $tpl->SetVariable('navigation', $this->GetNumberedPageNavigation($page, $limit, $total, 'ShowCategory', $params));
     $entries = $pModel->GetEntriesByCategory($catInfo['id'], $page);
     if (!Jaws_Error::IsError($entries)) {
         foreach ($entries as $entry) {
             $this->ShowEntry($tpl, 'view_category', $entry);
         }
     }
     $tpl->ParseBlock('view_category');
     return $tpl->Get();
 }
Beispiel #17
0
 /**
  * Creates and prints the template of Friends
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function Display()
 {
     $tpl = $this->gadget->template->load('Friends.html');
     $model = $this->gadget->model->load('Friends');
     $friends = $model->GetRandomFriends();
     if (!Jaws_Error::IsError($friends)) {
         $tpl->SetBlock('friends');
         $tpl->SetVariable('title', $this->gadget->title);
         foreach ($friends as $friend) {
             $tpl->SetBlock('friends/friend');
             $tpl->SetVariable('name', Jaws_XSS::filter($friend['friend']));
             $tpl->SetVariable('url', Jaws_XSS::filter($friend['url']));
             $tpl->ParseBlock('friends/friend');
         }
     }
     $tpl->ParseBlock('friends');
     return $tpl->Get();
 }
Beispiel #18
0
 /**
  * Creates a new note
  *
  * @access  public
  * @return  array   Response array
  */
 function CreateNote()
 {
     $data = jaws()->request->fetch(array('title', 'content'), 'post');
     if (empty($data['title']) || empty($data['content'])) {
         $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_ERROR_INCOMPLETE_DATA'), 'Notepad.Response', RESPONSE_ERROR, $data);
         Jaws_Header::Referrer();
     }
     $model = $this->gadget->model->load('Notepad');
     $data['user'] = (int) $GLOBALS['app']->Session->GetAttribute('user');
     $data['title'] = Jaws_XSS::defilter($data['title']);
     $data['content'] = Jaws_XSS::defilter($data['content']);
     $result = $model->Insert($data);
     if (Jaws_Error::IsError($result)) {
         $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_ERROR_NOTE_CREATE'), 'Notepad.Response', RESPONSE_ERROR, $data);
         Jaws_Header::Referrer();
     }
     $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_NOTICE_NOTE_CREATED'), 'Notepad.Response');
     Jaws_Header::Location($this->gadget->urlMap('Notepad'));
 }
Beispiel #19
0
 /**
  * Displays a block of pages belongs to the specified group
  *
  * @access  public
  * @param   mixed   $gid    ID or fast_url of the group (int/string)
  * @param   int     $orderBy
  * @param   int     $limit    limit show pages
  * @return  string  XHTML content
  */
 function GroupPages($gid = 0, $orderBy = 1, $limit = 0)
 {
     if (empty($gid)) {
         $get = $this->gadget->request->fetch(array('gid', 'order'), 'get');
         $gid = Jaws_XSS::defilter($get['gid']);
         $orderBy = $get['order'];
     }
     $pModel = $this->gadget->model->load('Page');
     $gModel = $this->gadget->model->load('Group');
     $group = $gModel->GetGroup($gid);
     if (Jaws_Error::IsError($group) || $group == null) {
         return false;
     }
     if (!$this->gadget->GetPermission('AccessGroup', $group['id'])) {
         return Jaws_HTTPError::Get(403);
     }
     $GLOBALS['app']->Layout->SetTitle($group['title']);
     $GLOBALS['app']->Layout->AddToMetaKeywords($group['meta_keywords']);
     $GLOBALS['app']->Layout->SetDescription($group['meta_description']);
     if (!is_numeric($gid)) {
         $gid = $group['id'];
     }
     $pages = $pModel->GetPages($gid, $limit, $orderBy, null, true);
     if (Jaws_Error::IsError($pages)) {
         return false;
     }
     $tpl = $this->gadget->template->load('StaticPage.html');
     $tpl->SetBlock('group_pages');
     $tpl->SetVariable('title', $group['title']);
     foreach ($pages as $page) {
         $param = array('gid' => empty($group['fast_url']) ? $group['id'] : $group['fast_url'], 'pid' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url']);
         $link = $this->gadget->urlMap('Pages', $param);
         $tpl->SetBlock('group_pages/item');
         $tpl->SetVariable('page', $page['title']);
         $tpl->SetVariable('link', $link);
         $tpl->ParseBlock('group_pages/item');
     }
     $tpl->ParseBlock('group_pages');
     return $tpl->Get();
 }
Beispiel #20
0
 /**
  * Prints all the files with their titles and contents of initial folder
  *
  * @access  public
  * @param   string  $path
  * @return  string  XHTML template content with titles and contents
  */
 function InitialFolder($path = '')
 {
     if (!$this->gadget->GetPermission('OutputAccess')) {
         return false;
     }
     if ($this->gadget->registry->fetch('frontend_avail') != 'true') {
         return false;
     }
     $tpl = $this->gadget->template->load('FileBrowser.html');
     $tpl->SetBlock('initial_folder');
     $tpl->SetVariable('title', $this->gadget->title);
     $model = $this->gadget->model->load('Directory');
     $items = $model->ReadDir($path);
     if (!Jaws_Error::IsError($items)) {
         foreach ($items as $item) {
             $tpl->SetBlock('initial_folder/item');
             $tpl->SetVariable('icon', $item['mini_icon']);
             $tpl->SetVariable('name', Jaws_XSS::filter($item['filename']));
             $tpl->SetVariable('title', Jaws_XSS::filter($item['title']));
             if ($item['is_dir']) {
                 $relative = Jaws_XSS::filter($item['relative']) . '/';
                 $url = $this->gadget->urlMap('Display', array('path' => $relative));
             } else {
                 if (empty($item['id'])) {
                     $url = Jaws_XSS::filter($item['url']);
                 } else {
                     $fid = empty($item['fast_url']) ? $item['id'] : Jaws_XSS::filter($item['fast_url']);
                     $url = $this->gadget->urlMap('Download', array('id' => $fid));
                 }
             }
             $tpl->SetVariable('url', $url);
             $tpl->ParseBlock('initial_folder/item');
         }
     }
     $tpl->ParseBlock('initial_folder');
     return $tpl->Get();
 }
Beispiel #21
0
 /**
  * Checks if fast_url already exists in a table, if it doesn't then it returns
  * the original fast_url (the param value). However, if it already exists then 
  * it starts looking for a 'valid' fast_url using the 'foobar-[1...n]' schema.
  *
  * @access  protected
  * @param   string     $fast_url     Fast URL
  * @param   string     $table        DB table name (without [[ ]])
  * @param   bool       $unique_check must be false in update methods
  * @param   string     $field        Table field where fast_url is stored
  * @return  string     Correct fast URL
  */
 public function GetRealFastURL($fast_url, $table, $unique_check = true, $field = 'fast_url')
 {
     if (is_numeric($fast_url)) {
         $fast_url = '-' . $fast_url . '-';
     }
     $fast_url = Jaws_UTF8::trim(Jaws_XSS::defilter($fast_url));
     $fast_url = preg_replace(array('#[^\\p{L}[:digit:]_\\.\\-\\s]#u', '#[\\s_\\-]#u', '#\\-\\+#u'), array('', '-', '-'), Jaws_UTF8::strtolower($fast_url));
     $fast_url = Jaws_UTF8::substr($fast_url, 0, 90);
     if (!$unique_check) {
         return $fast_url;
     }
     $tblReg = Jaws_ORM::getInstance()->table($table);
     $result = $tblReg->select("count({$field})")->where($field, $fast_url . '%', 'like')->fetchOne();
     if (Jaws_Error::IsError($result) || empty($result)) {
         return $fast_url;
     }
     return $fast_url . '-' . $result;
 }
Beispiel #22
0
 /**
  * Displays the weather of a specific region
  *
  * @access  public
  * @param   int      $region     Region ID
  * @param   bool     $forecast   Whether displays forecast or not
  * @return  string   XHTML content
  */
 function RegionWeather($region = null, $forecast = false)
 {
     $region_get = $this->gadget->request->fetch('id', 'get');
     $region_get = Jaws_XSS::defilter($region_get);
     if (!empty($region_get)) {
         $region = $region_get;
         $forecast = true;
     }
     $model = $this->gadget->model->load('Regions');
     $region = $model->GetRegion($region);
     if (Jaws_Error::IsError($region) || empty($region)) {
         return false;
     }
     $tpl = $this->gadget->template->load('Weather.html');
     $tpl->SetBlock('weather');
     $options = array();
     $options['timeout'] = (int) $this->gadget->registry->fetch('connection_timeout', 'Settings');
     if ($this->gadget->registry->fetch('proxy_enabled', 'Settings') == 'true') {
         if ($this->gadget->registry->fetch('proxy_auth', 'Settings') == 'true') {
             $options['proxy_user'] = $this->gadget->registry->fetch('proxy_user', 'Settings');
             $options['proxy_pass'] = $this->gadget->registry->fetch('proxy_pass', 'Settings');
         }
         $options['proxy_host'] = $this->gadget->registry->fetch('proxy_host', 'Settings');
         $options['proxy_port'] = $this->gadget->registry->fetch('proxy_port', 'Settings');
     }
     require_once JAWS_PATH . 'gadgets/Weather/include/Underground.php';
     $metric = $this->gadget->registry->fetchByUser('unit') == 'metric';
     $wService = new Underground_Weather($this->gadget->registry->fetch('api_key'), $metric, JAWS_DATA . 'weather', $this->gadget->registry->fetch('update_period'), $options);
     $rWeather = $wService->getWeather($region['latitude'], $region['longitude']);
     if (!PEAR::isError($rWeather)) {
         $tpl->SetVariable('title', _t('WEATHER_REGION', $region['title']));
         $rid = empty($region['fast_url']) ? $region['id'] : $region['fast_url'];
         $url = $this->gadget->urlMap('RegionWeather', array('id' => $rid));
         $tpl->SetVariable('url', $url);
         $tpl->SetBlock('weather/current');
         if ($forecast) {
             $tpl->SetBlock('weather/current/head');
             $tpl->SetVariable('lbl_current', _t('WEATHER_CURRENT'));
             $tpl->ParseBlock('weather/current/head');
         }
         $tpl->SetVariable('url', $url);
         $tpl->SetVariable('temp', $rWeather['temp']);
         $tpl->SetVariable('unit', $metric ? _t('WEATHER_UNIT_METRIC_TEMP') : _t('WEATHER_UNIT_IMPERIAL_TEMP'));
         $tpl->SetVariable('alt', $rWeather['icon']);
         $tpl->SetVariable('icon', "gadgets/Weather/Resources/images/states/{$rWeather['icon']}.png");
         $tpl->ParseBlock('weather/current');
         if ($forecast) {
             $GLOBALS['app']->Layout->SetTitle(_t('WEATHER_REGION', $region['title']));
             $GLOBALS['app']->Layout->AddToMetaKeywords($this->gadget->title . ',' . $region['title']);
             $objDate = Jaws_Date::getInstance();
             $tpl->SetBlock('weather/forecast');
             $tpl->SetVariable('lbl_forecast', _t('WEATHER_FORECAST'));
             $dFormat = $this->gadget->registry->fetchByUser('date_format');
             foreach ($rWeather['forecast'] as $dayIndex => $fWeather) {
                 $tpl->SetBlock('weather/forecast/item');
                 //86400 = 3600 * 24
                 $tpl->SetVariable('forecast_date', $objDate->Format(time() + $dayIndex * 86400, $dFormat));
                 $tpl->SetVariable('lbl_low', _t('WEATHER_LOW'));
                 $tpl->SetVariable('low_temp', $fWeather['low']);
                 $tpl->SetVariable('lbl_high', _t('WEATHER_HIGH'));
                 $tpl->SetVariable('high_temp', $fWeather['high']);
                 $tpl->SetVariable('unit', $metric ? _t('WEATHER_UNIT_METRIC_TEMP') : _t('WEATHER_UNIT_IMPERIAL_TEMP'));
                 $tpl->SetVariable('alt', $fWeather['icon']);
                 $tpl->SetVariable('icon', "gadgets/Weather/Resources/images/states/{$fWeather['icon']}.png");
                 $tpl->ParseBlock('weather/forecast/item');
             }
             $tpl->ParseBlock('weather/forecast');
         }
     } else {
         $GLOBALS['log']->Log(JAWS_LOG_ERROR, $rWeather->getMessage());
     }
     $tpl->ParseBlock('weather');
     return $tpl->Get();
 }
Beispiel #23
0
 /**
  * Adds a new emblem
  *
  * @access  public
  * @see     EmblemsModel->AddEmblem()
  */
 function AddEmblem()
 {
     $post = jaws()->request->fetch(array('title', 'url', 'type', 'published'), 'post');
     $post['url'] = Jaws_XSS::defilter($post['url']);
     $res = Jaws_Utils::UploadFiles($_FILES, JAWS_DATA . 'emblems/', 'jpg,gif,swf,png,jpeg,bmp,svg');
     if (Jaws_Error::IsError($res)) {
         $GLOBALS['app']->Session->PushLastResponse($res->getMessage(), RESPONSE_ERROR);
     } elseif (empty($res)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_ERROR_NO_IMAGE_UPLOADED'), RESPONSE_ERROR);
     } else {
         $post['image'] = $res['image'][0]['host_filename'];
         $post['published'] = (bool) $post['published'];
         $model = $this->gadget->model->loadAdmin('Emblems');
         $res = $model->AddEmblem($post);
         if (Jaws_Error::IsError($res)) {
             Jaws_Utils::delete(JAWS_DATA . 'emblems/' . $post['image']);
             $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_ERROR_NOT_ADDED'), RESPONSE_ERROR);
         } else {
             $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_ADDED'), RESPONSE_NOTICE);
         }
     }
     Jaws_Header::Location(BASE_SCRIPT . '?gadget=Emblems');
 }
Beispiel #24
0
 /**
  * Displays banners(all-time visibles and random ones)
  *
  * @access  public
  * @param   int     $gid    Group ID
  * @return  string  XHTML template content
  */
 function Banners($gid = 0)
 {
     $id = (int) $this->gadget->request->fetch('id', 'get');
     $abs_url = false;
     if (!empty($id)) {
         $gid = $id;
         header(Jaws_XSS::filter($_SERVER['SERVER_PROTOCOL']) . " 200 OK");
         $abs_url = true;
     }
     $groupModel = $this->gadget->model->load('Groups');
     $group = $groupModel->GetGroup($gid);
     if (Jaws_Error::IsError($group) || empty($group) || !$group['published']) {
         return false;
     }
     $bannerModel = $this->gadget->model->load('Banners');
     $banners = $bannerModel->GetVisibleBanners($gid, $group['limit_count']);
     if (Jaws_Error::IsError($banners) || empty($banners)) {
         return false;
     }
     $tpl = $this->gadget->template->load('Banners.html');
     switch ($group['show_type']) {
         case 1:
         case 2:
             $type_block = 'banners_type_' . $group['show_type'];
             break;
         default:
             $type_block = 'banners';
     }
     $tpl->SetBlock($type_block);
     $tpl->SetVariable('gid', $gid);
     if ($group['show_title']) {
         $tpl->SetBlock("{$type_block}/title");
         $tpl->SetVariable('title', _t('BANNER_ACTIONS_BANNERS_TITLE', $group['title']));
         $tpl->ParseBlock("{$type_block}/title");
     }
     foreach ($banners as $banner) {
         $tpl->SetBlock("{$type_block}/banner");
         $tpl_template = new Jaws_Template();
         $tpl_template->LoadFromString('<!-- BEGIN x -->' . $banner['template'] . '<!-- END x -->');
         $tpl_template->SetBlock('x');
         $tpl_template->SetVariable('title', $banner['title']);
         if (file_exists(JAWS_DATA . $this->gadget->DataDirectory . $banner['banner'])) {
             $tpl_template->SetVariable('banner', $GLOBALS['app']->getDataURL($this->gadget->DataDirectory . $banner['banner']));
         } else {
             $tpl_template->SetVariable('banner', $banner['banner']);
         }
         if (empty($banner['url'])) {
             $tpl_template->SetVariable('link', 'javascript:void(0);');
             $tpl_template->SetVariable('target', '_self');
         } else {
             $tpl_template->SetVariable('link', $this->gadget->urlMap('Click', array('id' => $banner['id']), $abs_url));
             $tpl_template->SetVariable('target', '_blank');
         }
         $tpl_template->ParseBlock('x');
         $tpl->SetVariable('template', $tpl_template->Get());
         unset($tpl_template);
         $tpl->ParseBlock("{$type_block}/banner");
         $bannerModel->ViewBanner($banner['id']);
     }
     $tpl->ParseBlock($type_block);
     return $tpl->Get();
 }
Beispiel #25
0
 /**
  * Providing download file
  *
  * @access  public
  * @param   string  $fpath      File path
  * @param   string  $fname      File name
  * @param   string  $mimetype   File mime type
  * @param   string  $inline     Inline disposition?
  * @return  bool    Returns TRUE on success or FALSE on failure
  */
 static function Download($fpath, $fname, $mimetype = '', $inline = true)
 {
     if (false === ($fhandle = @fopen($fpath, 'rb'))) {
         return false;
     }
     $fsize = @filesize($fpath);
     $fstart = 0;
     $fstop = $fsize - 1;
     if (isset($_SERVER['HTTP_RANGE']) && !empty($_SERVER['HTTP_RANGE'])) {
         $frange = explode('-', substr($_SERVER['HTTP_RANGE'], strlen('bytes=')));
         $fstart = (int) $frange[0];
         if (isset($frange[1]) && $frange[1] > 0) {
             $fstop = (int) $frange[1];
         }
         header(Jaws_XSS::filter($_SERVER['SERVER_PROTOCOL']) . " 206 Partial Content");
         header('Content-Range: bytes ' . $fstart . '-' . $fstop . '/' . $fsize);
     }
     // ranges unit
     header("Accept-Ranges: bytes");
     // browser must download file from server instead of cache
     header("Expires: 0");
     header("Pragma: public");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     // content mime type
     if (empty($mimetype)) {
         // force download dialog
         header("Content-Type: application/force-download");
     } else {
         header("Content-Type: {$mimetype}");
     }
     // content disposition and filename
     $disposition = $inline ? 'inline' : 'attachment';
     header("Content-Disposition: {$disposition}; filename={$fname}");
     // content length
     header("Content-Transfer-Encoding: binary");
     header('Content-Length: ' . ($fstop - $fstart + 1));
     //jump to start position
     if ($fstart > 0) {
         fseek($fhandle, $fstart);
     }
     $fposition = $fstart;
     while (!feof($fhandle) && !connection_aborted() && connection_status() == 0 && $fposition <= $fstop) {
         $fposition += 64 * 1024;
         //64 kbytes
         print fread($fhandle, 64 * 1024);
         flush();
     }
     fclose($fhandle);
     return true;
 }
Beispiel #26
0
 /**
  * Create ATOM struct of a given category
  *
  * @access  public
  * @param   int     $category   Category ID
  * @param   string  $feed_type  OPTIONAL feed type
  * @return  mixed   Can return the Atom Object or Jaws_Error on error
  */
 function GetCategoryAtomStruct($category, $feed_type = 'atom')
 {
     $model = $this->gadget->model->load('Categories');
     $catInfo = $model->GetCategory($category);
     if (Jaws_Error::IsError($catInfo)) {
         return new Jaws_Error(_t('BLOG_ERROR_GETTING_CATEGORIES_ATOMSTRUCT'));
     }
     $now = Jaws_DB::getInstance()->date();
     $blogTable = Jaws_ORM::getInstance()->table('blog');
     $blogTable->select('blog.id:integer', 'user_id:integer', 'blog_entrycat.category_id:integer', 'username', 'email', 'nickname', 'title', 'fast_url', 'summary', 'text', 'blog.publishtime', 'blog.updatetime', 'clicks:integer', 'comments:integer', 'allow_comments:boolean', 'published:boolean')->join('users', 'blog.user_id', 'users.id')->join('blog_entrycat', 'blog.id', 'blog_entrycat.entry_id');
     $blogTable->where('published', true)->and()->where('blog.publishtime', $now, '<=');
     $blogTable->and()->where('blog_entrycat.category_id', $catInfo['id']);
     $result = $blogTable->orderby('blog.publishtime desc')->fetchAll();
     if (Jaws_Error::IsError($result)) {
         return new Jaws_Error(_t('BLOG_ERROR_GETTING_CATEGORIES_ATOMSTRUCT'));
     }
     $cid = empty($catInfo['fast_url']) ? $catInfo['id'] : Jaws_XSS::filter($catInfo['fast_url']);
     $categoryAtom = new Jaws_AtomFeed();
     $siteURL = $GLOBALS['app']->GetSiteURL('/');
     $url = $this->gadget->urlMap($feed_type == 'atom' ? 'ShowAtomCategory' : 'ShowRSSCategory', array('id' => $cid), true);
     $categoryAtom->SetTitle($this->gadget->registry->fetch('site_name', 'Settings'));
     $categoryAtom->SetLink($url);
     $categoryAtom->SetId($siteURL);
     $categoryAtom->SetTagLine($catInfo['name']);
     $categoryAtom->SetAuthor($this->gadget->registry->fetch('site_author', 'Settings'), $siteURL, $this->gadget->registry->fetch('gate_email', 'Settings'));
     $categoryAtom->SetGenerator('JAWS ' . $GLOBALS['app']->Registry->fetch('version'));
     $categoryAtom->SetCopyright($this->gadget->registry->fetch('site_copyright', 'Settings'));
     $objDate = Jaws_Date::getInstance();
     foreach ($result as $r) {
         $entry = new AtomEntry();
         $entry->SetTitle($r['title']);
         $post_id = empty($r['fast_url']) ? $r['id'] : $r['fast_url'];
         $url = $this->gadget->urlMap('SingleView', array('id' => $post_id), true);
         $entry->SetLink($url);
         $entry->SetId($url);
         $summary = $r['summary'];
         $text = $r['text'];
         // for compatibility with old versions
         $more_pos = Jaws_UTF8::strpos($text, '[more]');
         if ($more_pos !== false) {
             $summary = Jaws_UTF8::substr($text, 0, $more_pos);
             $text = Jaws_UTF8::str_replace('[more]', '', $text);
             // Update this entry to split summary and body of post
             $model = $this->gadget->model->load('Posts');
             $model->SplitEntry($r['id'], $summary, $text);
         }
         $summary = empty($summary) ? $text : $summary;
         $summary = $this->gadget->ParseText($summary);
         $text = $this->gadget->ParseText($text);
         $entry->SetSummary($summary, 'html');
         $entry->SetContent($text, 'html');
         $email = $r['email'];
         $entry->SetAuthor($r['nickname'], $categoryAtom->Link->HRef, $email);
         $entry->SetPublished($objDate->ToISO($r['publishtime']));
         $entry->SetUpdated($objDate->ToISO($r['updatetime']));
         $categoryAtom->AddEntry($entry);
         if (!isset($last_modified)) {
             $last_modified = $r['updatetime'];
         }
     }
     if (isset($last_modified)) {
         $categoryAtom->SetUpdated($objDate->ToISO($last_modified));
     } else {
         $categoryAtom->SetUpdated($objDate->ToISO(date('Y-m-d H:i:s')));
     }
     return $categoryAtom;
 }
Beispiel #27
0
 /**
  * Get HTTP status reponse
  *
  * @access  public
  * @param   int     $code       Status code
  * @param   string  $title      Reponse page title
  * @param   string  $message    Response message
  * @return  string  HTML template content
  */
 static function Get($code, $title = null, $message = null)
 {
     header('Content-Type: text/html; charset=utf-8');
     header('Cache-Control: no-cache, must-revalidate');
     header('Pragma: no-cache');
     // Let everyone know a HTTP error has been happened
     $result = $GLOBALS['app']->Listener->Shout('HTTPError', 'HTTPError', $code, 'UrlMapper');
     if (!Jaws_Error::IsError($result) && !empty($result)) {
         $code = empty($result['code']) ? $code : $result['code'];
     }
     switch ($code) {
         case 401:
             $realm = $GLOBALS['app']->Registry->fetch('realm', 'Settings');
             jaws()->http_response_code(401);
             // using invalid authentication type for avoid popup login box
             header('WWW-Authenticate: LoginBox realm="' . $realm . '"');
             $urlLogin = $GLOBALS['app']->Map->GetURLFor('Users', 'LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(true))));
             $title = empty($title) ? _t('GLOBAL_HTTP_ERROR_TITLE_401') : $title;
             $message = empty($message) ? _t('GLOBAL_HTTP_ERROR_CONTENT_401', $urlLogin) : $message;
             break;
         case 403:
             jaws()->http_response_code(403);
             $title = empty($title) ? _t('GLOBAL_HTTP_ERROR_TITLE_403') : $title;
             $message = empty($message) ? _t('GLOBAL_HTTP_ERROR_CONTENT_403') : $message;
             break;
         case 404:
             $uri = Jaws_XSS::filter(Jaws_Utils::getRequestURL(false));
             if (empty($message)) {
                 $message = _t('GLOBAL_HTTP_ERROR_CONTENT_404', $uri);
             }
             jaws()->http_response_code(404);
             $title = empty($title) ? _t('GLOBAL_HTTP_ERROR_TITLE_404') : $title;
             break;
         case 410:
             jaws()->http_response_code(410);
             $title = empty($title) ? _t('GLOBAL_HTTP_ERROR_TITLE_410') : $title;
             $message = empty($message) ? _t('GLOBAL_HTTP_ERROR_CONTENT_410') : $message;
             break;
         case 500:
             jaws()->http_response_code(500);
             $title = empty($title) ? _t('GLOBAL_HTTP_ERROR_TITLE_500') : $title;
             $message = empty($message) ? _t('GLOBAL_HTTP_ERROR_CONTENT_500') : $message;
             break;
         case 503:
             jaws()->http_response_code(503);
             $title = empty($title) ? _t('GLOBAL_HTTP_ERROR_TITLE_503') : $title;
             $message = empty($message) ? _t('GLOBAL_HTTP_ERROR_CONTENT_503') : $message;
             break;
         default:
             $title = empty($title) ? _t("GLOBAL_HTTP_ERROR_TITLE_{$code}") : $title;
             $message = empty($message) ? _t("GLOBAL_HTTP_ERROR_CONTENT_{$code}") : $message;
     }
     // if current theme has a error code html file, return it, if not return the messages.
     $theme = $GLOBALS['app']->GetTheme();
     $site_name = $GLOBALS['app']->Registry->fetch('site_name', 'Settings');
     if (file_exists($theme['path'] . "{$code}.html")) {
         $tpl = new Jaws_Template();
         $tpl->Load("{$code}.html", $theme['path']);
         $tpl->SetBlock($code);
         //set global site config
         $direction = _t('GLOBAL_LANG_DIRECTION');
         $dir = $direction == 'rtl' ? '.' . $direction : '';
         $brow = $GLOBALS['app']->GetBrowserFlag();
         $brow = empty($brow) ? '' : '.' . $brow;
         $tpl->SetVariable('.dir', $dir);
         $tpl->SetVariable('.browser', $brow);
         $tpl->SetVariable('site-name', $site_name);
         $tpl->SetVariable('site-title', $site_name);
         $tpl->SetVariable('site-slogan', $GLOBALS['app']->Registry->fetch('site_slogan', 'Settings'));
         $tpl->SetVariable('site-author', $GLOBALS['app']->Registry->fetch('site_author', 'Settings'));
         $tpl->SetVariable('site-copyright', $GLOBALS['app']->Registry->fetch('copyright', 'Settings'));
         $tpl->SetVariable('site-description', $GLOBALS['app']->Registry->fetch('site_description', 'Settings'));
         $tpl->SetVariable('title', $title);
         $tpl->SetVariable('content', $message);
         $tpl->ParseBlock($code);
         return $tpl->Get();
     }
     return "<div class=\"gadget_header\"><div class=\"gadget_title\"><h3>{$title}</h3></div></div>" . "<div class=\"gadget_container\"><div class=\"content\">{$message}</div></div>";
 }
Beispiel #28
0
 /**
  * Displays search results
  *
  * @access  public
  * @return  string  XHTML content of search results
  */
 function Results()
 {
     $tpl = $this->gadget->template->load('Results.html');
     $tpl->SetBlock('results');
     $tpl->SetVariable('title', _t('SEARCH_RESULTS'));
     $post = jaws()->request->fetch(array('gadgets', 'all', 'exact', 'least', 'exclude', 'date'), 'get');
     $page = jaws()->request->fetch('page', 'get');
     if (is_null($page) || !is_numeric($page) || $page <= 0) {
         $page = 1;
     }
     $searchable = false;
     $model = $this->gadget->model->load('Search');
     $options = $model->parseSearch($post, $searchable);
     if ($searchable) {
         $items = $model->Search($options);
     }
     $query_string = '?gadget=Search&action=Results';
     foreach ($post as $option => $value) {
         if (!empty($value)) {
             $query_string .= '&' . $option . '=' . $value;
         }
     }
     $query_string .= '&page=';
     $results_limit = (int) $this->gadget->registry->fetch('results_limit');
     if (empty($results_limit)) {
         $results_limit = 10;
     }
     if (!$searchable) {
         $tpl->SetBlock('results/notfound');
         $min_key_len = $this->gadget->registry->fetch('Search/min_key_len');
         $tpl->SetVariable('message', _t('SEARCH_STRING_TOO_SHORT', $min_key_len));
         $tpl->ParseBlock('results/notfound');
     } elseif (count($items) > 1) {
         $tpl->SetVariable('navigation', $this->GetNumberedPageNavigation($page, $results_limit, $items['_totalItems'], $query_string));
         if (count($items) > 2) {
             $tpl->SetBlock('results/subtitle');
             $tpl->SetVariable('text', _t('SEARCH_RESULTS_SUBTITLE', $items['_totalItems'], $model->implodeSearch()));
             $tpl->ParseBlock('results/subtitle');
         }
         unset($items['_totalItems']);
         $date = Jaws_Date::getInstance();
         $max_result_len = (int) $this->gadget->registry->fetch('max_result_len');
         if (empty($max_result_len)) {
             $max_result_len = 500;
         }
         $item_counter = 0;
         foreach ($items as $gadget => $result) {
             $tpl->SetBlock('results/gadget');
             $info = Jaws_Gadget::getInstance($gadget);
             $tpl->SetVariable('gadget_result', _t('SEARCH_RESULTS_IN_GADGETS', count($result), $model->implodeSearch(), $info->title));
             $tpl->ParseBlock('results/gadget');
             foreach ($result as $item) {
                 $item_counter++;
                 if ($item_counter <= ($page - 1) * $results_limit || $item_counter > $page * $results_limit) {
                     continue;
                 }
                 $tpl->SetBlock('results/item');
                 $tpl->SetVariable('title', $item['title']);
                 $tpl->SetVariable('url', $item['url']);
                 $tpl->SetVariable('target', isset($item['outer']) && $item['outer'] ? '_blank' : '_self');
                 $tpl->SetVariable('image', $item['image']);
                 if (!isset($item['parse_text']) || $item['parse_text']) {
                     $item['snippet'] = $this->gadget->ParseText($item['snippet'], $gadget);
                 }
                 if (!isset($item['strip_tags']) || $item['strip_tags']) {
                     $item['snippet'] = strip_tags($item['snippet']);
                 }
                 $item['snippet'] = Jaws_UTF8::substr($item['snippet'], 0, $max_result_len);
                 $tpl->SetVariable('snippet', $item['snippet']);
                 $tpl->SetVariable('date', $date->Format($item['date']));
                 $tpl->ParseBlock('results/item');
             }
         }
     } else {
         $tpl->SetBlock('results/notfound');
         header(Jaws_XSS::filter($_SERVER['SERVER_PROTOCOL']) . " 404 Not Found");
         $tpl->SetVariable('message', _t('SEARCH_NO_RESULTS', $model->implodeSearch()));
         $tpl->ParseBlock('results/notfound');
     }
     $tpl->ParseBlock('results');
     return $tpl->Get();
 }
Beispiel #29
0
 /**
  * Send email to recipient
  *
  * @access  public
  * @param   string   $to   Recipient email address
  * @param   int      $cid   Contact ID
  * @return  mixed    True on Success or Jaws_Error on Failure
  */
 function SendEmailToRecipient($to, $cid)
 {
     $model = $this->gadget->model->load('Contacts');
     $contact = $model->GetContact($cid);
     if (Jaws_Error::IsError($contact)) {
         return $contact;
     }
     if (!isset($contact['id'])) {
         return new Jaws_Error(_t('CONTACT_ERROR_CONTACT_DOES_NOT_EXISTS'));
     }
     $from_name = $contact['name'];
     $from_email = $contact['email'];
     $site_url = $GLOBALS['app']->getSiteURL('/');
     $site_name = $this->gadget->registry->fetch('site_name', 'Settings');
     $format = $this->gadget->registry->fetch('email_format');
     if ($format == 'html') {
         $message = Jaws_String::AutoParagraph($contact['msg_txt']);
     } else {
         $message = $contact['msg_txt'];
     }
     $tpl = $this->gadget->template->load('SendToRecipient.html');
     $tpl->SetBlock($format);
     $tpl->SetVariable('lbl_name', _t('GLOBAL_NAME'));
     $tpl->SetVariable('lbl_email', _t('GLOBAL_EMAIL'));
     $tpl->SetVariable('lbl_company', _t('CONTACT_COMPANY'));
     $tpl->SetVariable('lbl_url', _t('GLOBAL_URL'));
     $tpl->SetVariable('lbl_tel', _t('CONTACT_TEL'));
     $tpl->SetVariable('lbl_fax', _t('CONTACT_FAX'));
     $tpl->SetVariable('lbl_mobile', _t('CONTACT_MOBILE'));
     $tpl->SetVariable('lbl_address', _t('CONTACT_ADDRESS'));
     $tpl->SetVariable('lbl_recipient', _t('CONTACT_RECIPIENT'));
     $tpl->SetVariable('lbl_subject', _t('CONTACT_SUBJECT'));
     $tpl->SetVariable('lbl_message', _t('CONTACT_MESSAGE'));
     $tpl->SetVariable('name', $contact['name']);
     $tpl->SetVariable('email', $contact['email']);
     $tpl->SetVariable('company', $contact['company']);
     $tpl->SetVariable('url', $contact['url']);
     $tpl->SetVariable('tel', $contact['tel']);
     $tpl->SetVariable('fax', $contact['fax']);
     $tpl->SetVariable('mobile', $contact['mobile']);
     $tpl->SetVariable('address', $contact['address']);
     $tpl->SetVariable('recipient', $to);
     $tpl->SetVariable('subject', $contact['subject']);
     $tpl->SetVariable('message', $message);
     $tpl->SetVariable('site-name', $site_name);
     $tpl->SetVariable('site-url', $site_url);
     $tpl->ParseBlock($format);
     $template = $tpl->Get();
     $mail = Jaws_Mail::getInstance();
     $mail->SetFrom($from_email, $from_name);
     $mail->AddRecipient($to);
     $mail->SetSubject(Jaws_XSS::defilter($contact['subject']));
     $mail->SetBody($template, $format);
     $result = $mail->send();
     if (Jaws_Error::IsError($result)) {
         return $result;
     }
     return true;
 }
Beispiel #30
0
 /**
  * Send contact reply
  *
  * @access  public
  * @param   int     $cid    Contact ID
  * @return  mixed   True on Success or Jaws_Error on Failure
  */
 function SendReply($cid)
 {
     $model = $this->gadget->model->loadAdmin('Contacts');
     $contact = $model->GetReply($cid);
     if (Jaws_Error::IsError($contact)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR);
         return new Jaws_Error(_t('GLOBAL_ERROR_QUERY_FAILED'));
     }
     if (!isset($contact['id'])) {
         $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_CONTACT_DOES_NOT_EXISTS'), RESPONSE_ERROR);
         return new Jaws_Error(_t('CONTACT_ERROR_CONTACT_DOES_NOT_EXISTS'));
     }
     $from_name = '';
     $from_email = '';
     $to = $contact['email'];
     $rid = $contact['recipient'];
     if ($rid != 0) {
         $rModel = $this->gadget->model->load('Recipients');
         $recipient = $rModel->GetRecipient($rid);
         if (Jaws_Error::IsError($recipient)) {
             $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR);
             return new Jaws_Error(_t('GLOBAL_ERROR_QUERY_FAILED'));
         }
         if (!isset($recipient['id'])) {
             $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_RECIPIENT_DOES_NOT_EXISTS'), RESPONSE_ERROR);
             return new Jaws_Error(_t('CONTACT_ERROR_RECIPIENT_DOES_NOT_EXISTS'));
         }
         $from_name = $recipient['name'];
         $from_email = $recipient['email'];
     }
     $format = $this->gadget->registry->fetch('email_format');
     if ($format == 'html') {
         $reply = $this->gadget->ParseText($contact['reply']);
     } else {
         $reply = $contact['reply'];
     }
     $jDate = Jaws_Date::getInstance();
     $site_url = $GLOBALS['app']->getSiteURL('/');
     $site_name = $this->gadget->registry->fetch('site_name', 'Settings');
     $site_language = $this->gadget->registry->fetch('site_language', 'Settings');
     $profile_url = $GLOBALS['app']->getSiteURL('/') . $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $GLOBALS['app']->Session->GetAttribute('username')));
     Jaws_Translate::getInstance()->LoadTranslation('Global', JAWS_COMPONENT_OTHERS, $site_language);
     Jaws_Translate::getInstance()->LoadTranslation('Contact', JAWS_COMPONENT_GADGET, $site_language);
     $tpl = $this->gadget->template->load('SendReplyTo.html', array('loadFromTheme' => true, 'loadRTLDirection' => _t_lang($site_language, 'GLOBAL_LANG_DIRECTION') == 'rtl'));
     $tpl->SetBlock($format);
     $tpl->SetVariable('lbl_name', _t_lang($site_language, 'GLOBAL_NAME'));
     $tpl->SetVariable('lbl_email', _t_lang($site_language, 'GLOBAL_EMAIL'));
     $tpl->SetVariable('lbl_message', _t_lang($site_language, 'CONTACT_MESSAGE'));
     $tpl->SetVariable('lbl_reply', _t_lang($site_language, 'CONTACT_REPLY'));
     $tpl->SetVariable('name', $contact['name']);
     $tpl->SetVariable('email', $contact['email']);
     $tpl->SetVariable('subject', $contact['subject']);
     $tpl->SetVariable('message', $contact['msg_txt']);
     $tpl->SetVariable('reply', $reply);
     $tpl->SetVariable('createtime', $jDate->Format($contact['createtime']));
     $tpl->SetVariable('nickname', $GLOBALS['app']->Session->GetAttribute('nickname'));
     $tpl->SetVariable('profile_url', $profile_url);
     $tpl->SetVariable('site-name', $site_name);
     $tpl->SetVariable('site-url', $site_url);
     $tpl->ParseBlock($format);
     $template = $tpl->Get();
     $subject = _t_lang($site_language, 'CONTACT_REPLY_TO', Jaws_XSS::defilter($contact['subject']));
     $mail = Jaws_Mail::getInstance();
     $mail->SetFrom($from_email, $from_name);
     $mail->AddRecipient($to);
     $mail->AddRecipient('', 'cc');
     $mail->SetSubject($subject);
     $mail->SetBody($template, $format);
     $result = $mail->send();
     if (Jaws_Error::IsError($result)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_REPLY_NOT_SENT'), RESPONSE_ERROR);
         return false;
     }
     $model->UpdateReplySent($cid, true);
     $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_REPLY_SENT'), RESPONSE_NOTICE);
     return true;
 }