Example #1
0
 /**
  * Parse the correct messages into the template
  */
 protected function parse()
 {
     parent::parse();
     // grab the error-type from the parameters
     $errorType = $this->getParameter('type');
     // set correct headers
     switch ($errorType) {
         case 'module-not-allowed':
         case 'action-not-allowed':
             SpoonHTTP::setHeadersByCode(403);
             break;
         case 'not-found':
             SpoonHTTP::setHeadersByCode(404);
             break;
     }
     // querystring provided?
     if ($this->getParameter('querystring') !== null) {
         // split into file and parameters
         $chunks = explode('?', $this->getParameter('querystring'));
         // get extension
         $extension = SpoonFile::getExtension($chunks[0]);
         // if the file has an extension it is a non-existing-file
         if ($extension != '' && $extension != $chunks[0]) {
             // set correct headers
             SpoonHTTP::setHeadersByCode(404);
             // give a nice error, so we can detect which file is missing
             echo 'Requested file (' . htmlspecialchars($this->getParameter('querystring')) . ') not found.';
             // stop script execution
             exit;
         }
     }
     // assign the correct message into the template
     $this->tpl->assign('message', BL::err(SpoonFilter::toCamelCase(htmlspecialchars($errorType), '-')));
 }
Example #2
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         $fields = $this->frm->getFields();
         $fields['email']->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             //--Get the mail
             $mailing = BackendMailengineModel::get($this->id);
             //--Get the template
             $template = BackendMailengineModel::getTemplate($mailing['template_id']);
             //--Create basic mail
             $text = BackendMailengineModel::createMail($mailing, $template);
             $mailing['from_email'] = $template['from_email'];
             $mailing['from_name'] = html_entity_decode($template['from_name']);
             $mailing['reply_email'] = $template['reply_email'];
             $mailing['reply_name'] = html_entity_decode($template['reply_name']);
             $emails = explode(',', $fields['email']->getValue());
             if (!empty($emails)) {
                 foreach ($emails as $email) {
                     $email = trim($email);
                     if (\SpoonFilter::isEmail($email)) {
                         //--Send test mailing
                         BackendMailengineModel::sendMail(html_entity_decode($mailing['subject']), $text, $email, 'Test Recepient', $mailing);
                     }
                 }
             }
             //--Redirect
             \SpoonHTTP::redirect(BackendModel::createURLForAction('index', $this->module) . "&id=" . $this->id . "&report=TestEmailSend");
         }
     }
     $this->frm->parse($this->tpl);
 }
Example #3
0
 /**
  * Output a CSV-file as a download
  *
  * @param string $filename					The name of the file.
  * @param array $array						The array to convert.
  * @param array[optional] $columns			The column names you want to use.
  * @param array[optional] $excludeColumns	The columns you want to exclude.
  */
 public static function outputCSV($filename, array $array, array $columns = null, array $excludeColumns = null)
 {
     // get settings
     $splitCharacter = BackendAuthentication::getUser()->getSetting('csv_split_character');
     $lineEnding = BackendAuthentication::getUser()->getSetting('csv_line_ending');
     // reformat
     if ($lineEnding == '\\n') {
         $lineEnding = "\n";
     }
     if ($lineEnding == '\\r\\n') {
         $lineEnding = "\r\n";
     }
     // convert into CSV
     $csv = SpoonFileCSV::arrayToString($array, $columns, $excludeColumns, $splitCharacter, '"', $lineEnding);
     // set headers for download
     $headers[] = 'Content-type: application/csv; charset=' . SPOON_CHARSET;
     $headers[] = 'Content-Disposition: attachment; filename="' . $filename;
     $headers[] = 'Content-Length: ' . strlen($csv);
     $headers[] = 'Pragma: no-cache';
     // overwrite the headers
     SpoonHTTP::setHeaders($headers);
     // ouput the CSV
     echo $csv;
     exit;
 }
Example #4
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // init vars
     $templates = array();
     $theme = BackendModel::getModuleSetting('core', 'theme');
     $files[] = BACKEND_PATH . '/core/layout/editor_templates/templates.js';
     $themePath = FRONTEND_PATH . '/themes/' . $theme . '/core/layout/editor_templates/templates.js';
     if (SpoonFile::exists($themePath)) {
         $files[] = $themePath;
     }
     // loop all files
     foreach ($files as $file) {
         // process file
         $templates = array_merge($templates, $this->processFile($file));
     }
     // set headers
     SpoonHTTP::setHeaders('Content-type: text/javascript');
     // output the templates
     if (!empty($templates)) {
         echo 'CKEDITOR.addTemplates(\'default\', { imagesPath: \'/\', templates:' . "\n";
         echo json_encode($templates) . "\n";
         echo '});';
     }
     exit;
 }
Example #5
0
 /**
  * Parse the ical and output into the browser.
  *
  * @param bool[optional] $headers Should the headers be set? (Use false if you're debugging).
  */
 public function parse($headers = true)
 {
     // set headers
     if ((bool) $headers) {
         SpoonHTTP::setHeaders('Content-Disposition: inline; filename=' . SpoonFilter::urlise($this->getTitle()) . '.ics');
     }
     // call the parent
     parent::parse($headers);
 }
Example #6
0
 /**
  * Parse the iCal and output into the browser.
  *
  * @param bool $headers Should the headers be set? (Use false if you're debugging).
  */
 public function parse($headers = true)
 {
     // set headers
     if ((bool) $headers) {
         \SpoonHTTP::setHeaders('Content-Disposition: inline; filename=' . CommonUri::getUrl($this->getTitle()) . '.ics');
     }
     // call the parent
     parent::parse($headers);
 }
 /**
  * Export the templates as XML.
  */
 protected function parse()
 {
     $xml = Model::createTemplateXmlForExport($this->selectedTheme);
     $filename = 'templates_' . BackendModel::getUTCDate('d-m-Y') . '.xml';
     $headers = array('Content-type: text/xml', 'Content-disposition: attachment; filename="' . $filename . '"');
     \SpoonHTTP::setHeaders($headers);
     echo $xml;
     exit;
 }
Example #8
0
 /**
  * Output the template into the browser
  * Will also assign the interfacelabels and all user-defined constants.
  *
  * @param string $template The path for the template.
  * @param bool[optional] $customHeaders Are there custom headers set?
  */
 public function display($template, $customHeaders = false)
 {
     $this->parseConstants();
     $this->parseAuthenticatedUser();
     $this->parseDebug();
     $this->parseLabels();
     $this->parseLocale();
     $this->parseVars();
     // parse headers
     if (!$customHeaders) {
         SpoonHTTP::setHeaders('Content-type: text/html;charset=' . SPOON_CHARSET);
     }
     parent::display($template);
 }
 /**
  * Create the XML based on the locale items.
  */
 private function createXML()
 {
     $charset = BackendModel::getContainer()->getParameter('kernel.charset');
     // create XML
     $xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
     // xml headers
     $headers[] = 'Content-Disposition: attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"';
     $headers[] = 'Content-Type: application/octet-stream;charset=' . $charset;
     $headers[] = 'Content-Length: ' . strlen($xmlOutput);
     // set headers
     \SpoonHTTP::setHeaders($headers);
     // output XML
     echo $xmlOutput;
     exit;
 }
Example #10
0
 /**
  * Create the XML based on the locale items.
  *
  * @return	void
  */
 private function createXML()
 {
     // create XML
     $xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
     // xml headers
     $headers[] = 'Content-Disposition: attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"';
     $headers[] = 'Content-Type: application/octet-stream;charset=utf-8';
     $headers[] = 'Content-Length: ' . strlen($xmlOutput);
     // set headers
     SpoonHTTP::setHeaders($headers);
     // output XML
     echo $xmlOutput;
     // stop script
     exit;
 }
Example #11
0
 /**
  * Create the CSV.
  *
  * @return	void
  */
 private function createCsv()
 {
     // create csv
     $csv = SpoonFileCSV::arrayToString($this->rows, $this->columnHeaders);
     // set headers for download
     $headers[] = 'Content-type: application/csv; charset=utf-8';
     $headers[] = 'Content-Disposition: attachment; filename="' . date('Ymd_His') . '.csv"';
     $headers[] = 'Content-Length: ' . strlen($csv);
     $headers[] = 'Pragma: no-cache';
     // overwrite the headers
     SpoonHTTP::setHeaders($headers);
     // output
     echo $csv;
     // exit here
     exit;
 }
Example #12
0
 /**
  * Check if all required settings have been set
  *
  * @param string $module The module.
  */
 public function __construct($module)
 {
     parent::__construct($module);
     $error = false;
     $action = Spoon::exists('url') ? Spoon::get('url')->getAction() : null;
     // analytics session token
     if (BackendModel::getModuleSetting('analytics', 'session_token') === null) {
         $error = true;
     }
     // analytics table id
     if (BackendModel::getModuleSetting('analytics', 'table_id') === null) {
         $error = true;
     }
     // missing settings, so redirect to the index-page to show a message (except on the index- and settings-page)
     if ($error && $action != 'settings' && $action != 'index') {
         SpoonHTTP::redirect(BackendModel::createURLForAction('index'));
     }
 }
Example #13
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['text'] = $this->frm->getField('text')->getValue();
             $item['street'] = $this->frm->getField('street')->getValue();
             $item['number'] = $this->frm->getField('number')->getValue();
             $item['zip'] = $this->frm->getField('zip')->getValue();
             $item['city'] = $this->frm->getField('city')->getValue();
             $item['country'] = $this->frm->getField('country')->getValue();
             // geocode address
             $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['street'] . ' ' . $item['number'] . ', ' . $item['zip'] . ' ' . $item['city'] . ', ' . SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false';
             $geocode = json_decode(SpoonHTTP::getContent($url));
             $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
             $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
             // insert the item
             $id = BackendLocationModel::insert($item);
             // add search index
             // if(is_callable(array('BackendSearchModel', 'addIndex'))) BackendSearchModel::addIndex($this->getModule(), (int) $id, array('title' => $item['title'], 'text' => $item['text']));
             // everything is saved, so redirect to the overview
             if ($item['lat'] && $item['lng']) {
                 // trigger event
                 BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
                 // redirect
                 $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $id);
             } else {
                 $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $id);
             }
         }
     }
 }
Example #14
0
 /**
  * You have to specify the action and module so we know what to do with this instance
  *
  * @param string $action The action to load.
  * @param string $module The module to load.
  */
 public function __construct($action, $module)
 {
     $this->setModule($module);
     $this->setAction($action);
     $this->loadConfig();
     $allowed = false;
     // is this an allowed action
     if (BackendAuthentication::isAllowedAction($action, $this->getModule())) {
         $allowed = true;
     }
     // is this an allowed AJAX-action?
     if (!$allowed) {
         // set correct headers
         SpoonHTTP::setHeadersByCode(403);
         // output
         $fakeAction = new BackendBaseAJAXAction('', '');
         $fakeAction->output(BackendBaseAJAXAction::FORBIDDEN, null, 'Not logged in.');
     }
 }
Example #15
0
 /**
  * Validate form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         if ($this->frm->isCorrect()) {
             if (!empty($this->records)) {
                 $teller = 0;
                 foreach ($this->records as $key => $record) {
                     if ($teller < $this->frm->getField("number_of_items")->getValue()) {
                         $data = array();
                         //--Create url
                         $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($record['address'] . ', ' . $record['zipcode'] . ' ' . $record['city'] . ', ' . \SpoonLocale::getCountry($record['country'], BL::getWorkingLanguage())) . '&sensor=false';
                         //--Get lat
                         $geocode = json_decode(\SpoonHTTP::getContent($url));
                         //--Sleep between the requests
                         sleep(0.05);
                         //--Check result
                         $data['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
                         $data['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
                         if ($data['lat'] != null) {
                             BackendAddressesModel::update($record['id'], $data);
                             $this->response .= "<strong>" . $record['company'] . "</strong> - " . $record['address'] . " " . $record['zipcode'] . " " . $record['city'] . " <i>(Lat: " . $data['lat'] . ", Lng: " . $data['lng'] . ")</i><br/>";
                             //--Delete from array
                             unset($this->records[$key]);
                         } else {
                             $data['lat'] = "notfound";
                             $data['lng'] = "notfound";
                             BackendAddressesModel::update($record['id'], $data);
                             $this->responseError .= "<strong>" . $record['company'] . "</strong> - " . $record['address'] . " " . $record['zipcode'] . " " . $record['city'] . "<br/>";
                         }
                     } else {
                         break;
                     }
                     //--Add teller
                     $teller++;
                 }
                 $this->tpl->assign("responseError", $this->responseError);
                 $this->tpl->assign("response", $this->response);
             }
         }
     }
 }
Example #16
0
 /**
  * Output the template into the browser
  * Will also assign the interfacelabels and all user-defined constants.
  *
  * @return	void
  * @param	string $template				The path for the template.
  * @param	bool[optional] $customHeaders	Are there custom headers set?
  */
 public function display($template, $customHeaders = false)
 {
     // parse constants
     $this->parseConstants();
     // parse authenticated user
     $this->parseAuthenticatedUser();
     // check debug
     $this->parseDebug();
     // parse the label
     $this->parseLabels();
     // parse locale
     $this->parseLocale();
     // parse some vars
     $this->parseVars();
     // parse headers
     if (!$customHeaders) {
         SpoonHTTP::setHeaders('Content-type: text/html;charset=utf-8');
     }
     // call the parent
     parent::display($template);
 }
Example #17
0
 /**
  * Sets the headers so we may download the CSV file in question
  *
  * @param string $path The full path to the CSV file you wish to download.
  * @return array
  */
 private function downloadCSV($path)
 {
     // check if the file exists
     if (!SpoonFile::exists($path)) {
         throw new SpoonFileException('The file ' . $path . ' doesn\'t exist.');
     }
     // fetch the filename from the path string
     $explodedFilename = explode('/', $path);
     $filename = end($explodedFilename);
     // set headers for download
     $headers[] = 'Content-type: application/csv; charset=' . SPOON_CHARSET;
     $headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
     $headers[] = 'Pragma: no-cache';
     // overwrite the headers
     SpoonHTTP::setHeaders($headers);
     // get the file contents
     $content = SpoonFile::getContent($path);
     // output the file contents
     echo $content;
     exit;
 }
Example #18
0
 /**
  * Validate the form based on the variables in $_POST
  *
  * @return	void
  */
 private function validateForm()
 {
     // form submitted
     if ($this->frm->isSubmitted()) {
         // required fields
         $this->frm->getField('email')->isEmail('Please provide a valid e-mailaddress.');
         $this->frm->getField('password')->isFilled('This field is required.');
         $this->frm->getField('confirm')->isFilled('This field is required.');
         if ($this->frm->getField('password')->getValue() != $this->frm->getField('confirm')->getValue()) {
             $this->frm->getField('confirm')->addError('The passwords do not match.');
         }
         // all valid
         if ($this->frm->isCorrect()) {
             // update session
             SpoonSession::set('email', $this->frm->getField('email')->getValue());
             SpoonSession::set('password', $this->frm->getField('password')->getValue());
             SpoonSession::set('confirm', $this->frm->getField('confirm')->getValue());
             // redirect
             SpoonHTTP::redirect('index.php?step=7');
         }
     }
 }
Example #19
0
 /**
  * Reads an feed into a SpoonRSS object.
  *
  * @return	SpoonRSS					Returns as an instance of SpoonRSS.
  * @param	string $URL					An URL where the feed is located or the XML of the feed.
  * @param	string[optional] $type		The type of feed, possible values are: url, string.
  */
 public static function readFromFeed($URL, $type = 'url')
 {
     // redefine var
     $URL = (string) $URL;
     $type = (string) SpoonFilter::getValue($type, array('url', 'string'), 'url');
     // validate
     if ($type == 'url' && !SpoonFilter::isURL($URL)) {
         throw new SpoonFeedException('This (' . SpoonFilter::htmlentities($URL) . ') isn\'t a valid URL.');
     }
     if (!self::isValid($URL, $type)) {
         throw new SpoonFeedException('Invalid feed');
     }
     // load xmlstring
     if ($type == 'url') {
         $xmlString = SpoonHTTP::getContent($URL);
     } else {
         $xmlString = $URL;
     }
     // convert to simpleXML
     $XML = @simplexml_load_string($xmlString);
     // validate the feed
     if ($XML === false) {
         throw new SpoonFeedException('Invalid rss-string.');
     }
     // get title, link and description
     $title = (string) $XML->channel->title;
     $link = (string) $XML->channel->link;
     $description = (string) $XML->channel->description;
     // create instance
     $RSS = new SpoonFeedRSS($title, $link, $description);
     // add items
     foreach ($XML->channel->item as $item) {
         // try to read
         try {
             // read xml
             $item = SpoonFeedRSSItem::readFromXML($item);
             $RSS->addItem($item);
         } catch (Exception $e) {
             // ignore exceptions
         }
     }
     // add category
     if (isset($XML->channel->category)) {
         foreach ($XML->channel->category as $category) {
             if (isset($category['domain'])) {
                 $RSS->addCategory((string) $category, (string) $category['domain']);
             } else {
                 $RSS->addCategory((string) $category);
             }
         }
     }
     // add skip day
     if (isset($XML->channel->skipDays)) {
         // loop ski-days
         foreach ($XML->channel->skipDays->day as $day) {
             // try to add
             try {
                 // add skip-day
                 $RSS->addSkipDay((string) $day);
             } catch (Exception $e) {
                 // ignore exceptions
             }
         }
     }
     // add skip hour
     if (isset($XML->channel->skipHours)) {
         foreach ($XML->channel->skipHours->hour as $hour) {
             // try to add
             try {
                 // add skip hour
                 $RSS->addSkipHour((int) $hour);
             } catch (Exception $e) {
                 // ignore exceptions
             }
         }
     }
     // set cloud
     if (isset($XML->channel->cloud['domain']) && isset($XML->channel->cloud['port']) && isset($XML->channel->cloud['path']) && isset($XML->channel->cloud['registerProce-dure']) && isset($XML->channel->cloud['protocol'])) {
         // read attributes
         $cloudDomain = (string) $XML->channel->cloud['domain'];
         $cloudPort = (int) $XML->channel->cloud['port'];
         $cloudPath = (string) $XML->channel->cloud['path'];
         $cloudRegisterProcedure = (string) $XML->channel->cloud['registerProce-dure'];
         $cloudProtocol = (string) $XML->channel->cloud['protocol'];
         // set property
         $RSS->setCloud($cloudDomain, $cloudPort, $cloudPath, $cloudRegisterProcedure, $cloudProtocol);
     }
     // set copyright
     if (isset($XML->channel->copyright)) {
         $copyright = (string) $XML->channel->copyright;
         $RSS->setCopyright($copyright);
     }
     // set docs
     if (isset($XML->channel->docs)) {
         $docs = (string) $XML->channel->docs;
         $RSS->setDocs($docs);
     }
     // set generator if it is present
     if (isset($XML->channel->generator)) {
         $generator = (string) $XML->channel->generator;
         $RSS->setGenerator($generator);
     }
     // set image if it is present
     if (isset($XML->channel->image->title) && isset($XML->channel->image->url) && isset($XML->channel->image->link)) {
         // read properties
         $imageTitle = (string) $XML->channel->image->title;
         $imageURL = (string) $XML->channel->image->url;
         $imageLink = (string) $XML->channel->image->link;
         // read optional properties
         if (isset($XML->channel->image->width)) {
             $imageWidth = (int) $XML->channel->image->width;
         } else {
             $imageWidth = null;
         }
         if (isset($XML->channel->image->height)) {
             $imageHeight = (int) $XML->channel->image->height;
         } else {
             $imageHeight = null;
         }
         if (isset($XML->channel->image->description)) {
             $imageDescription = (string) $XML->channel->image->description;
         } else {
             $imageDescription = null;
         }
         // try to set image
         try {
             // set image
             $RSS->setImage($imageURL, $imageTitle, $imageLink, $imageWidth, $imageHeight, $imageDescription);
         } catch (Exception $e) {
             // ignore exceptions
         }
     }
     // set language if its is present
     if (isset($XML->channel->language)) {
         $language = (string) $XML->channel->language;
         $RSS->setLanguage($language);
     }
     // set last build date if it is present
     if (isset($XML->channel->lastBuildDate)) {
         $lastBuildDate = (int) strtotime($XML->channel->lastBuildDate);
         $RSS->setLastBuildDate($lastBuildDate);
     }
     // set managing editor
     if (isset($XML->channel->managingEditor)) {
         $managingEditor = (string) $XML->channel->managingEditor;
         $RSS->setManagingEditor($managingEditor);
     }
     // set publication date
     if (isset($XML->channel->pubDate)) {
         $publicationDate = (int) strtotime($XML->channel->pubDate);
         $RSS->setPublicationDate($publicationDate);
     }
     // set rating
     if (isset($XML->channel->rating)) {
         $rating = (string) $XML->channel->rating;
         $RSS->setRating($rating);
     }
     // set ttl
     if (isset($XML->channel->ttl)) {
         $ttl = (int) $XML->channel->ttl;
         $RSS->setTTL($ttl);
     }
     // set webmaster
     if (isset($XML->channel->webmaster)) {
         $webmaster = (string) $XML->channel->webmaster;
         $RSS->setWebmaster($webmaster);
     }
     // return
     return $RSS;
 }
Example #20
0
 /**
  * This method will be called by the Spoon Exception handler and is specific for exceptions thrown in AJAX-actions
  *
  * @param object $exception The exception that was thrown.
  * @param string $output    The output that should be mailed.
  */
 public static function exceptionAJAXHandler($exception, $output)
 {
     \SpoonHTTP::setHeaders('content-type: application/json');
     $response = array('code' => $exception->getCode() != 0 ? $exception->getCode() : 500, 'message' => $exception->getMessage());
     echo json_encode($response);
     exit;
 }
Example #21
0
                $userFollowing->fb_uid = 1;
            }
            array_push($following, get_object_vars($userFollowing));
        }
        $tpl->assign('oFollowing', true);
        $tpl->assign('iFollowing', $following);
    } else {
        $tpl->assign('oNoFollowing', true);
    }
    if ($user->GetFollowers() != null) {
        $values = $user->GetFollowers();
        $followers = array();
        foreach ($values as $value) {
            $userFollower = new User($value['user_id']);
            if ($userFollower->fb_uid == null) {
                $userFollower->fb_uid = 1;
            }
            array_push($followers, get_object_vars($userFollower));
        }
        $tpl->assign('oFollowers', true);
        $tpl->assign('iFollowers', $followers);
    } else {
        $tpl->assign('oNoFollowers', true);
    }
} else {
    //GTFO!!!
    SpoonHTTP::redirect('index.php');
}
// show the output
$tpl->assign('content', $tpl->getContent('templates/dashboardFriends.tpl'));
$tpl->display('templates/layout.tpl');
Example #22
0
 /**
  * Validate the form based on the variables in $_POST
  */
 private function validateForm()
 {
     // form submitted
     if ($this->frm->isSubmitted()) {
         // multiple languages
         if ($this->frm->getField('language_type')->getValue() == 'multiple') {
             // list of languages
             $languages = $this->frm->getField('languages')->getValue();
             // default language
             if (!in_array($this->frm->getField('default_language')->getValue(), $languages)) {
                 $this->frm->getField('default_language')->setError('Your default language needs to be in the list of languages you chose.');
             }
         } else {
             // list of languages
             $languages = (array) array($this->frm->getField('default_language')->getValue());
         }
         // same cms interface language
         if ($this->frm->getField('same_interface_language')->getChecked()) {
             // list of languages
             $interfaceLanguages = $languages;
         } else {
             // list of languages
             $interfaceLanguages = $this->frm->getField('interface_languages')->getValue();
         }
         // default language
         if (!in_array($this->frm->getField('default_interface_language')->getValue(), $interfaceLanguages)) {
             $this->frm->getField('default_interface_language')->setError('Your default language needs to be in the list of languages you chose.');
         }
         // all valid
         if ($this->frm->isCorrect()) {
             // set languages
             SpoonSession::set('default_language', $this->frm->getField('default_language')->getValue());
             SpoonSession::set('default_interface_language', $this->frm->getField('default_interface_language')->getValue());
             SpoonSession::set('multiple_languages', $this->frm->getField('language_type')->getValue() == 'multiple' ? true : false);
             SpoonSession::set('languages', $languages);
             SpoonSession::set('interface_languages', $interfaceLanguages);
             // redirect
             SpoonHTTP::redirect('index.php?step=4');
         }
     }
 }
Example #23
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // submitted
     if ($this->frm->isSubmitted()) {
         // does the key exists?
         if (SpoonSession::exists('formbuilder_' . $this->item['id'])) {
             // calculate difference
             $diff = time() - (int) SpoonSession::get('formbuilder_' . $this->item['id']);
             // calculate difference, it it isn't 10 seconds the we tell the user to slow down
             if ($diff < 10 && $diff != 0) {
                 $this->frm->addError(FL::err('FormTimeout'));
             }
         }
         // validate fields
         foreach ($this->item['fields'] as $field) {
             // fieldname
             $fieldName = 'field' . $field['id'];
             // skip
             if ($field['type'] == 'submit' || $field['type'] == 'paragraph' || $field['type'] == 'heading') {
                 continue;
             }
             // loop other validations
             foreach ($field['validations'] as $rule => $settings) {
                 // already has an error so skip
                 if ($this->frm->getField($fieldName)->getErrors() !== null) {
                     continue;
                 }
                 // required
                 if ($rule == 'required') {
                     $this->frm->getField($fieldName)->isFilled($settings['error_message']);
                 } elseif ($rule == 'email') {
                     // only check this if the field is filled, if the field is required it will be validated before
                     if ($this->frm->getField($fieldName)->isFilled()) {
                         $this->frm->getField($fieldName)->isEmail($settings['error_message']);
                     }
                 } elseif ($rule == 'numeric') {
                     // only check this if the field is filled, if the field is required it will be validated before
                     if ($this->frm->getField($fieldName)->isFilled()) {
                         $this->frm->getField($fieldName)->isNumeric($settings['error_message']);
                     }
                 }
             }
         }
         // valid form
         if ($this->frm->isCorrect()) {
             // item
             $data['form_id'] = $this->item['id'];
             $data['session_id'] = SpoonSession::getSessionId();
             $data['sent_on'] = FrontendModel::getUTCDate();
             $data['data'] = serialize(array('server' => $_SERVER));
             // insert data
             $dataId = FrontendFormBuilderModel::insertData($data);
             // init fields array
             $fields = array();
             // loop all fields
             foreach ($this->item['fields'] as $field) {
                 // skip
                 if ($field['type'] == 'submit' || $field['type'] == 'paragraph' || $field['type'] == 'heading') {
                     continue;
                 }
                 // field data
                 $fieldData['data_id'] = $dataId;
                 $fieldData['label'] = $field['settings']['label'];
                 $fieldData['value'] = $this->frm->getField('field' . $field['id'])->getValue();
                 // prepare fields for email
                 if ($this->item['method'] == 'database_email') {
                     // add field for email
                     $emailFields[] = array('label' => $field['settings']['label'], 'value' => is_array($fieldData['value']) ? implode(',', $fieldData['value']) : nl2br($fieldData['value']));
                 }
                 // clean up
                 if (is_array($fieldData['value']) && empty($fieldData['value'])) {
                     $fieldData['value'] = null;
                 }
                 // serialize
                 if ($fieldData['value'] !== null) {
                     $fieldData['value'] = serialize($fieldData['value']);
                 }
                 // save fields data
                 $fields[] = $fieldData;
                 // insert
                 FrontendFormBuilderModel::insertDataField($fieldData);
             }
             // need to send mail
             if ($this->item['method'] == 'database_email') {
                 // build variables
                 $variables['sentOn'] = time();
                 $variables['name'] = $this->item['name'];
                 $variables['fields'] = $emailFields;
                 // loop recipients
                 foreach ($this->item['email'] as $address) {
                     // add email
                     FrontendMailer::addEmail(sprintf(FL::getMessage('FormBuilderSubject'), $this->item['name']), FRONTEND_MODULES_PATH . '/form_builder/layout/templates/mails/form.tpl', $variables, $address, $this->item['name']);
                 }
             }
             // trigger event
             FrontendModel::triggerEvent('form_builder', 'after_submission', array('form_id' => $this->item['id'], 'data_id' => $dataId, 'data' => $data, 'fields' => $fields, 'visitorId' => FrontendModel::getVisitorId()));
             // store timestamp in session so we can block excesive usage
             SpoonSession::set('formbuilder_' . $this->item['id'], time());
             // redirect
             $redirect = SITE_URL . '/' . $this->URL->getQueryString();
             $redirect .= stripos($redirect, '?') === false ? '?' : '&';
             $redirect .= 'identifier=' . $this->item['identifier'];
             // redirect with identifier
             SpoonHTTP::redirect($redirect);
         } else {
             // global form errors set
             if ($this->frm->getErrors() != '') {
                 $this->tpl->assign('formBuilderError', $this->frm->getErrors());
             } else {
                 $this->tpl->assign('formBuilderError', FL::err('FormError'));
             }
         }
     }
 }
Example #24
0
 /**
  * Set the module
  *
  * We can't rely on the parent setModule function, because a cronjob requires no login
  *
  * @param string $module The module to load.
  */
 public function setModule($module)
 {
     // does this module exist?
     $modules = SpoonDirectory::getList(BACKEND_MODULES_PATH);
     $modules[] = 'core';
     if (!in_array($module, $modules)) {
         // set correct headers
         SpoonHTTP::setHeadersByCode(403);
         // throw exception
         throw new BackendException('Module not allowed.');
     }
     // set property
     $this->module = $module;
 }
Example #25
0
 /**
  * This method will be called by the Spoon Exceptionhandler and is specific for exceptions thrown in JS-files parsed through PHP
  *
  * @return	void
  * @param	object $exception	The exception that was thrown.
  * @param	string $output		The output that should be mailed.
  */
 public static function exceptionJSHandler($exception, $output)
 {
     // redefine
     $output = (string) $output;
     // set correct headers
     SpoonHTTP::setHeaders('content-type: application/javascript');
     // output
     echo '// ' . $exception->getMessage();
     // stop script execution
     exit;
 }
Example #26
0
 /**
  * Set the module
  *
  * We can't rely on the parent setModule function, because a cronjob requires no login
  *
  * @param string $module The module to load.
  */
 public function setModule($module)
 {
     // does this module exist?
     $modules = BackendModel::getModulesOnFilesystem();
     if (!in_array($module, $modules)) {
         // set correct headers
         \SpoonHTTP::setHeadersByCode(403);
         // throw exception
         throw new Exception('Module not allowed.');
     }
     // set property
     $this->module = $module;
 }
Example #27
0
 /**
  * Redirect to the loading page after checking for infinite loops.
  *
  * @return	void
  * @param	string $action							The action to check for infinite loops.
  * @param	array[optional] $extraParameters		The extra parameters to append to the redirect url.
  */
 public static function redirectToLoadingPage($action, array $extraParameters = array())
 {
     // get loop counter
     $counter = SpoonSession::exists($action . 'Loop') ? SpoonSession::get($action . 'Loop') : 0;
     // loop has run too long - throw exception
     if ($counter > 2) {
         throw new BackendException('An infinite loop has been detected while getting data from cache for the action "' . $action . '".');
     }
     // set new counter
     SpoonSession::set($action . 'Loop', ++$counter);
     // put parameters into a string
     $extraParameters = empty($extraParameters) ? '' : '&' . http_build_query($extraParameters);
     // redirect to loading page which will get the needed data based on the current action
     SpoonHTTP::redirect(BackendModel::createURLForAction('loading') . '&redirect_action=' . $action . $extraParameters);
 }
Example #28
0
 /**
  * Output as XML
  *
  * @return	void
  * @param	int $statusCode			The status code.
  * @param	array[optional] $data	The data to return.
  */
 private static function outputXML($statusCode, array $data = null)
 {
     // redefine
     $statusCode = (int) $statusCode;
     // init vars
     $pathChunks = explode('/', trim(dirname(__FILE__), '/'));
     $version = $pathChunks[count($pathChunks) - 2];
     // init XML
     $XML = new DOMDocument('1.0', 'utf-8');
     // set some properties
     $XML->preserveWhiteSpace = false;
     $XML->formatOutput = true;
     // create root element
     $root = $XML->createElement('fork');
     // add attributes
     $root->setAttribute('status_code', $statusCode);
     $root->setAttribute('status', $statusCode == 200 ? 'ok' : 'error');
     $root->setAttribute('version', FORK_VERSION);
     $root->setAttribute('endpoint', SITE_URL . '/api/' . $version);
     // append
     $XML->appendChild($root);
     // build XML
     array_walk($data, array('API', 'arrayToXML'), $root);
     // set correct headers
     SpoonHTTP::setHeadersByCode($statusCode);
     SpoonHTTP::setHeaders('content-type: text/xml;charset=utf-8');
     // output XML
     echo $XML->saveXML();
     // stop script execution
     exit;
 }
Example #29
0
 /**
  * Executes this step.
  */
 public function execute()
 {
     // extend execution limit
     set_time_limit(0);
     // validate all previous steps
     if (!$this->validateForm()) {
         SpoonHTTP::redirect('index.php?step=1');
     }
     // delete cached data
     $this->deleteCachedData();
     // create configuration files
     $this->createConfigurationFiles();
     // init database
     $this->initDatabase();
     // define paths
     $this->definePaths();
     // install modules
     $this->installModules();
     // create locale cache
     $this->createLocaleFiles();
     // already installed
     SpoonFile::setContent(dirname(__FILE__) . '/../cache/installed.txt', date('Y-m-d H:i:s'));
     // show success message
     $this->showSuccess();
     // clear session
     SpoonSession::destroy();
     // show output
     $this->tpl->display('layout/templates/step_7.tpl');
 }
Example #30
0
if (SpoonSession::exists('id') === false) {
    SpoonHTTP::redirect('index.php');
}
$latestCheckIn = CheckIn::getLatestCheckinByUserId(SpoonSession::get('id'));
$daysAgo = (SpoonDate::getDate("m.d.j") - SpoonDate::getDate("m.d.j", strtotime($latestCheckIn->timestamp))) * 100;
$timeAgo = SpoonDate::getDate("H:i:s") - SpoonDate::getDate("H:i:s", strtotime($latestCheckIn->timestamp));
//If the checkin is within 5 hours
//if($timeAgo > -6){
$tpl->assign('oCheckIn', true);
if (SpoonFilter::getGetValue('event', null, '') === 'plus') {
    $latestCheckIn->AddTab(SpoonFilter::getGetValue('drinkid', null, ''));
    SpoonHTTP::redirect('checkin.php');
} else {
    if (SpoonFilter::getGetValue('event', null, '') === 'min') {
        $latestCheckIn->DeleteTab(SpoonFilter::getGetValue('drinkid', null, ''));
        SpoonHTTP::redirect('checkin.php');
    }
}
$tpl->assign('pub_id', $latestCheckIn->pub->pub_id);
$tpl->assign('name', $latestCheckIn->pub->name);
$tpl->assign('longitude', $latestCheckIn->pub->longitude);
$tpl->assign('latitude', $latestCheckIn->pub->latitude);
$tpl->assign('people', $latestCheckIn->pub->getNumberPeople());
$tpl->assign('checkins', $latestCheckIn->pub->getNumberCheckins());
$tabs = $latestCheckIn->getTabs();
if ($tabs[0] !== null) {
    $tpl->assign('iTabs', $tabs);
    $tpl->assign('oTabs', true);
} else {
    $tpl->assign('iTabs', array());
    $tpl->assign('oNoTabs', true);