/** * getInstance * * @return object */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new FCMS_Error(); } return self::$instance; }
/** * addChildOppositeSexParents * * Verifies that both parents are of opposite sex. * * @param array $data * * @return boolean */ function addChildOppositeSexParents($data) { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); if (empty($data['parentId2'])) { return true; } // Get parents sex if not provided if (empty($data['parentSex1']) || empty($data['parentSex2'])) { $sql = "SELECT `id`, `sex`\n FROM `fcms_users`\n WHERE `id` = ?\n UNION\n SELECT `id`, `sex`\n FROM `fcms_users`\n WHERE `id` = ?"; $params = array($data['parentId1'], $data['parentId2']); $parentsInfo = $fcmsDatabase->getRows($sql, $params); if ($parentsInfo === false) { return false; } $data['parentSex1'] = $parentsInfo[0]['sex']; $data['parentSex2'] = $parentsInfo[1]['sex']; } if ($data['parentSex1'] === $data['parentSex2']) { return false; } return true; }
/** * upgradeNewPassword * * Saves the password in the new format, deletes old pw. * * @param int $userId * @param string $password * * @return boolean */ function upgradeNewPassword($userId, $password) { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); // Hash the pw $hasher = new PasswordHash(8, FALSE); $hashedPassword = $hasher->HashPassword($password); $sql = "UPDATE `fcms_users`\n SET `password` = '0',\n `phpass` = ?\n WHERE `id` = ?"; $params = array($hashedPassword, $userId); if (!$fcmsDatabase->update($sql, $params)) { return false; } return true; }
/** * getUserPicasaSessionToken * * @param int $user * * @return void */ function getUserPicasaSessionToken($user) { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); $sql = "SELECT `picasa_session_token`\n FROM `fcms_user_settings`\n WHERE `user` = ?\n LIMIT 1"; $r = $fcmsDatabase->getRow($sql, $user); if ($r === false) { return null; } if (empty($r)) { return null; } return $r['picasa_session_token']; }
/** * updateLastRun * * @param date $now * @param string $type * * @return void */ function updateLastRun($now, $type) { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); // Update date we last ran this job $sql = "UPDATE `fcms_schedule`\n SET `lastrun` = '{$now}'\n WHERE `type` = '{$type}'"; if (!$fcmsDatabase->update($sql, array($now, $type))) { logError(__FILE__ . ' [' . __LINE__ . '] - Could not update last run date for ' . $type . ' job.'); die; } }
/** * getVideoComments * * Valid params: * * currentUserId - The current user's id. * id - The id of the video. * * @param string $url * @param string $params * * @return void */ function getVideoComments($url, $params) { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); $fcmsUser = new User($fcmsError, $fcmsDatabase); $comments = ''; if (!isset($params['id'])) { die("Missing Video ID or User ID for getVideoComments"); } $id = $params['id']; $sql = "SELECT c.`id`, c.`comment`, c.`created`, c.`updated`, u.`fname`, u.`lname`, c.`created_id`, u.`avatar`, u.`gravatar`, s.`timezone`\n FROM `fcms_video_comment` AS c\n LEFT JOIN `fcms_users` AS u ON c.`created_id` = u.`id`\n LEFT JOIN `fcms_user_settings` AS s ON u.`id` = s.`user`\n WHERE `video_id` = '{$id}' \n ORDER BY `updated`"; $rows = $fcmsDatabase->getRows($sql, $id); if ($rows === false) { $fcmsError->displayError(); return; } foreach ($rows as $row) { $del_comment = ''; $date = fixDate(T_('F j, Y g:i a'), $row['timezone'], $row['updated']); $displayname = $row['fname'] . ' ' . $row['lname']; $comment = $row['comment']; $avatarPath = getAvatarPath($row['avatar'], $row['gravatar']); if ($fcmsUser->id == $row['created'] || $fcmsUser->access < 2) { $del_comment .= '<input type="submit" name="delcom" id="delcom" ' . 'value="' . T_('Delete') . '" class="gal_delcombtn" title="' . T_('Delete this Comment') . '"/>'; } $comments .= ' <div class="comment"> <form class="delcom" action="' . $url . '" method="post"> ' . $del_comment . ' <img class="avatar" alt="avatar" src="' . $avatarPath . '"/> <b>' . $displayname . '</b> <span>' . $date . '</span> <p> ' . parse($comment) . ' </p> <input type="hidden" name="id" value="' . $row['id'] . '"> </form> </div>'; } return $comments; }
/** * displayUpgradeDatabase * * @return void */ function displayUpgradeDatabase() { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); $fcmsUpgrade = new Upgrade($fcmsError, $fcmsDatabase); $latestVersion = $_SESSION['latestVersion']; if (!$fcmsUpgrade->upgrade()) { // Jacked html, but should work displayHeader(); $fcmsError->displayError(); displayFooter(); return; } if (!$fcmsUpgrade->updateCurrentVersion($latestVersion)) { // Jacked html, but should work displayHeader(); $fcmsError->displayError(); displayFooter(); return; } header('Location: upgrade.php?manual=1'); }
/** * isLoggedIn * * Checks whether user is logged in or not. If user is logged in * it just returns, if not, it redirects to login screen. * returns boolean */ function isLoggedIn() { global $fcmsUser; $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); // User has a session if (isset($_SESSION['fcms_id'])) { $id = (int) $_SESSION['fcms_id']; $token = $_SESSION['fcms_token']; } elseif (isset($_COOKIE['fcms_cookie_id'])) { $_SESSION['fcms_id'] = (int) $_COOKIE['fcms_cookie_id']; $_SESSION['fcms_token'] = $_COOKIE['fcms_cookie_token']; $id = $_SESSION['fcms_id']; $token = $_SESSION['fcms_token']; } else { $url = basename($_SERVER["REQUEST_URI"]); header('Location: ' . URL_PREFIX . 'index.php?err=login&url=' . URL_PREFIX . $url); exit; } // Make sure id is a number if (!is_numeric($id)) { $url = basename($_SERVER["REQUEST_URI"]); header('Location: ' . URL_PREFIX . 'index.php?err=login&url=' . URL_PREFIX . $url); exit; } // Verify the token is good if (isValidLoginToken($id, $token)) { $sql = "SELECT `access` AS 'val'\n FROM `fcms_users`\n WHERE `id` = ?\n UNION ALL\n SELECT `value` AS 'val'\n FROM `fcms_config`\n WHERE `name` = ?"; $rows = $fcmsDatabase->getRows($sql, array($id, 'site_off')); if ($rows === false) { $error->displayError(); return; } $site_off = $rows[0]['val']; $access = $rows[1]['val']; // Site is off and your not an admin if ($site_off == 1 && $access > 1) { header('Location: ' . URL_PREFIX . 'index.php?err=off'); exit; } else { // Load logged in user $fcmsUser = new User($fcmsError, $fcmsDatabase); return; } } else { unset($_SESSION['fcms_id']); unset($_SESSION['fcms_token']); if (isset($_COOKIE['fcms_cookie_id'])) { setcookie('fcms_cookie_id', '', time() - 3600, '/'); setcookie('fcms_cookie_token', '', time() - 3600, '/'); } header('Location: ' . URL_PREFIX . 'index.php?err=login'); exit; } }
/** * fixDate * * Used to output all date/time info. Fixes timezone, dst and translation. * * @param string $dateFormat a string of the format of the date/time, PHP date * @param string $tzOffset the timezone offset from the current user * @param date $date the date to fix * @param int $userid optional, user id to get dst/tz from * * @return string the formatted and translated date */ function fixDate($dateFormat, $tzOffset = '', $date = '', $userid = '') { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); $fixedDate = $date; $dst = ''; if ($userid == '') { $userid = (int) $_SESSION['fcms_id']; } // Get DST $sql = "SELECT `dst` \n FROM `fcms_user_settings` \n WHERE `user` = ?"; $row = $fcmsDatabase->getRow($sql, $userid); if ($row === false) { return $fixedDate; } if ($row['dst'] > 0) { $dst = " +1 hours"; } // Fix Timezone / DST $fixedDate = gmdate("Y-m-d H:i:s", strtotime("{$fixedDate} {$tzOffset}{$dst}")); // Formate date $fixedDate = formatDate($dateFormat, $fixedDate); return $fixedDate; }
/** * getFamilyTreeClassName * * Returns the name of the appropriate family tree * avatar upload class name. * * @return string */ function getFamilyTreeClassName() { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); $fcmsUser = User::getInstance($fcmsError, $fcmsDatabase); $type = getUploaderType($fcmsUser->id); if ($type == 'plupload') { $className = 'PluploadUploadFamilyTree'; } else { if ($type == 'java') { $className = 'JavaUploadFamilyTree'; } else { $className = 'UploadFamilyTree'; } } return $className; }
/** * displayFeedPhotoGallery * * @return void */ function displayFeedPhotoGallery() { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); $url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']; $urlroot = $url; $pos = strrpos($url, "/"); if ($pos === false) { $pos = strrpos($url, "\\"); } if (!($pos === false)) { $urlroot = substr($url, 0, $pos); } $lastday = time() - 84 * 60 * 60 * 24; // 12 weeks $sql = "SELECT `caption`, p.`user`, `filename`, p.`date`, `name` \n FROM `fcms_gallery_photos` AS p, `fcms_category` As c\n WHERE p.`category` = c.`id` \n AND UNIX_TIMESTAMP(p.`date`) >= ?\n ORDER BY p.`date`"; $rows = $fcmsDatabase->getRows($sql, $lastday); if ($rows === false) { print "Error getting data."; return; } $output = "<?xml version=\"1.0\"?" . "> \n<rss version=\"2.0\"> \n<channel> \n<title>" . getSiteName() . " - " . T_('Photo Gallery') . "</title> \n<link>" . $url . "</link> \n<description>" . getSiteName() . " - " . T_('Photo Gallery') . " " . T_('RSS Feed') . "</description> \n<language>" . T_pgettext('Language Code for this translation', 'lang') . "</language> \n<managingEditor>" . getContactEmail() . "</managingEditor> \n"; if (count($rows) > 0) { foreach ($rows as $line) { $title = htmlentities($line['caption']); if ($title == "") { $title = htmlentities($line['name']); } $output .= "<item><title><![CDATA[{$title}]]></title> \n<pubDate>" . gmdate('D, d M Y H:i:s', strtotime($line['date'])) . " GMT</pubDate> \n<link>" . htmlentities($urlroot . "/gallery/photos/member" . $line['user'] . "/" . $line['filename']) . "</link> \n<description><![CDATA[<img src=\"{$urlroot}/gallery/photos/member" . $line['user'] . "/" . $line['filename'] . "\" border=\"0\" />]]></description> \n<enclosure url=\"" . $urlroot . "/gallery/photos/member" . $line['user'] . "/" . $line['filename'] . "\" type=\"" . returnMIMEType("./gallery/photos/member" . $line['user'] . "/" . $line['filename']) . "\" length=\"" . filesize("./gallery/photos/member" . $line['user'] . "/" . $line['filename']) . "\" /> \n<guid isPermaLink=\"true\"><![CDATA[" . $urlroot . "/gallery/photos/member" . $line['user'] . "/" . $line['filename'] . "]]></guid> \n</item> \n"; } } $output .= "</channel></rss>"; echo $output; }