function testCreation()
 {
     $formula = new Dataface_Record('formulas', array('formula_name' => 'Test'));
     $this->assertEquals('Test', $formula->val('formula_name'), 'Initialization of Dataface_Record didn\'t retain value.');
     $formula = new Dataface_Record('formulas', array('ingredients' => array(0 => array('ingredient_id' => 3, 'concentration' => 10, 'concentration_units' => 1, 'amount' => 10, 'amount_units' => 2, '__id__' => 'new', '__order__' => 0), '__loaded__' => 1)));
     $this->assertEquals(array(0 => array('ingredient_id' => 3, 'concentration' => 10, 'concentration_units' => 1, 'amount' => 10, 'amount_units' => 2, '__id__' => 'new', '__order__' => 0), '__loaded__' => 1), $formula->val('ingredients'), 'Initialization of Dataface_Record did not retain transient field value.');
 }
Exemple #2
0
 public static function decorateNewJob(SweteSite $site, Dataface_Record $rec)
 {
     require_once 'modules/tm/lib/XFTranslationMemory.php';
     try {
         SweteDb::q('start transaction');
         // First we need to create a translation memory for this job.
         $tm = XFTranslationMemory::createTranslationMemory('Job translation memory for site ' . $site->getRecord()->val('website_id') . ' ' . $site->getSourceLanguage() . '->' . $site->getDestinationLanguage(), $site->getSourceLanguage(), $site->getDestinationLanguage());
         $status = SweteJob::JOB_STATUS_NEW;
         if ($rec->val('assigned_to')) {
             $status = SweteJob::JOB_STATUS_ASSIGNED;
         }
         $rec->setValues(array('website_id' => $site->getRecord()->val('website_id'), 'date_created' => date('Y-m-d H:i:s'), 'job_status' => $status, 'translation_memory_id' => $tm->getRecord()->val('translation_memory_id'), 'source_language' => $site->getSourceLanguage(), 'destination_language' => $site->getDestinationLanguage()));
         //print_r($rec->vals());
         $res = $rec->save();
         if (PEAR::isError($res)) {
             //print_r($res);
             throw new Exception($res->getMessage(), $res->getCode());
         }
         if ($rec->val('posted_by')) {
             $res = df_q("insert ignore into job_roles (job_id, username, access_level) values ('" . addslashes($rec->val('job_id')) . "','" . addslashes($rec->val('posted_by')) . "','" . self::JOB_ROLE_OWNER . "')");
         }
         if ($rec->val('assigned_to')) {
             $res = df_q("insert ignore into job_roles (job_id, username, access_level) values ('" . addslashes($rec->val('job_id')) . "','" . addslashes($rec->val('assigned_to')) . "','" . self::JOB_ROLE_TRANSLATOR . "')");
         }
         SweteDb::q('commit');
         $out = new SweteJob($rec);
         $out->setTranslationMemory($tm);
         return $out;
     } catch (Exception $ex) {
         SweteDb::q('rollback');
         throw $ex;
     }
 }
Exemple #3
0
 function test_set_date()
 {
     $record = new Dataface_Record('Profiles', array('id' => 3));
     $record->setValue('lastlogin', "February 4 2005 12:36:15");
     $val = $record->val('lastlogin');
     $this->assertEquals(2005, $val['year']);
     $this->assertEquals(2, $val['month']);
     $this->assertEquals(4, $val['day']);
     $this->assertEquals(12, $val['hours']);
     $this->assertEquals(36, $val['minutes']);
     $this->assertEquals(15, $val['seconds']);
     $record->setValue('lastlogin', '2004-12-27 9:23:24');
     $val = $record->val('lastlogin');
     $this->assertEquals(2004, $val['year']);
     $this->assertEquals(12, $val['month']);
     $this->assertEquals(27, $val['day']);
     $this->assertEquals(9, $val['hours']);
     $this->assertEquals(23, $val['minutes']);
     $this->assertEquals(24, $val['seconds']);
 }
Exemple #4
0
 function evaluate($expr, $fieldname, Dataface_Record $record)
 {
     // Check the field type first.  If this is a numeric field
     // we evaluate with math
     // If it is a string, we evaluate with string functions
     // Chop the leading '='
     $expr = substr($expr, 1);
     $table = $record->table();
     if ($table->isInt($fieldname) or $table->isFloat($fieldname)) {
         // This field is a numeric field so we treat it like
         // a numeric operation
         $oldval = $record->val($fieldname);
         if (!$oldval) {
             $oldval = 0;
         }
         $expr = preg_replace('/\\$\\$/', $oldval, $expr);
         if (preg_match('/^[\\+\\-\\*\\/]/', $expr)) {
             // If expression begins with an operation, we apply
             // the old value as the first operand of this
             // operation.
             $expr = $oldval . $expr;
         }
         if (!preg_match('/^[0-9\\.\\*\\+\\/\\-\\^\\(\\) ]+$/', $expr)) {
             throw new Exception("Invalid arithmetic expression.");
         }
         @eval('$expr=' . $expr . ';');
         return $expr;
     } else {
         if ($table->isDate($fieldname)) {
             // This field is a date field so we treat it like a
             // date operation
             $oldtime = strtotime($record->strval($fieldname));
             return date($expr, $oldtime);
         } else {
             // We assume it is a string
             $oldval = $record->val($fieldname);
             $expr = preg_replace('/\\$\\$/', $oldval, $expr);
             return $expr;
         }
     }
 }
Exemple #5
0
 function testCrawlSite()
 {
     $s = new Dataface_Record('websites', array());
     $s->setValues(array('website_url' => 'http://solutions.weblite.ca/', 'source_language' => 'en', 'target_language' => 'fr', 'website_name' => 'Site 1 french', 'active' => 1, 'base_path' => '/fr/', 'host' => 'localhost'));
     $s->save();
     $site = SweteSite::loadSiteById($s->val('website_id'));
     $crawler = new SiteCrawler();
     $crawler->site = $site;
     $crawler->startingPoint = 'http://solutions.weblite.ca/';
     $crawler->depth = 3;
     $crawler->crawl();
     //print_r($crawler->root);
 }
Exemple #6
0
 function testPage()
 {
     $url = DATAFACE_SITE_URL . '/tests/testsites/site1/index.html';
     $site = new Dataface_Record('websites', array());
     $site->setValues(array('website_url' => df_absolute_url(DATAFACE_SITE_URL . '/tests/testsites/site1/'), 'source_language' => 'en', 'target_language' => 'fr', 'website_name' => 'Site 1 French', 'active' => 1, 'base_path' => DATAFACE_SITE_URL . '/proxies/site1/', 'host' => $_SERVER['HTTP_HOST']));
     $site->save();
     df_q("delete from site_text_filters where website_id='" . addslashes($site->val('website_id')) . "'");
     $server = new ProxyServer();
     $server->site = SweteSite::loadSiteById($site->val('website_id'));
     $server->SERVER = array('REQUEST_METHOD' => 'get');
     $server->URL = df_absolute_url(DATAFACE_SITE_URL . '/proxies/site1/index.html');
     $server->buffer = true;
     $server->handleRequest();
     $doc = new DOMDocument();
     $doc->loadHtml(file_get_contents('tests/testsites/site1_output/index.out.html'));
     $expected = $doc->saveHtml();
     //echo $server->contentBuffer;
     $doc2 = new DOMDocument();
     $doc2->loadHtml($server->contentBuffer);
     $actual = $doc2->saveHtml();
     //$this->assertEquals(trim($expected), trim($actual));
     // Cancelled this test because WTF!!!!  Even if I print the actual output, copy it to the file
     // and compare it to itself, it still fails!!!! WTF!!!!
 }
Exemple #7
0
 function afterCopy(Dataface_Record $orig, Dataface_Record $copy)
 {
     $rand = md5(rand(0, 1000000));
     $copytable = 'copy_' . $rand;
     $res = xf_db_query("create temporary table `{$copytable}` select * from formula_ingredients where formula_id='" . addslashes($orig->val('formula_id')) . "'", df_db());
     if (!$res) {
         throw new Exception(xf_db_error(df_db()));
     }
     $res = xf_db_query("update `{$copytable}` set formula_id='" . addslashes($copy->val('formula_id')) . "'", df_db());
     if (!$res) {
         throw new Exception(xf_db_error(df_db()));
     }
     $res = xf_db_query("insert into formula_ingredients select * from `{$copytable}`", df_db());
     if (!$res) {
         throw new Exception(xf_db_error(df_db()));
     }
     $res = xf_db_query("drop table `{$copytable}`", df_db());
     if (!$res) {
         throw new Exception(xf_db_error(df_db()));
     }
 }
Exemple #8
0
 /**
  * Handles the insertion of a new imported record.  This should parse the 
  * input file and place the strings appropriately into the translation_miss_log
  * table and the translation memory.
  * @param Dataface_Record $record
  */
 public function afterInsert(Dataface_Record $record)
 {
     $filePath = $record->getContainerSource('file');
     if (!file_exists($filePath)) {
         throw new Exception("Source file doesn't exist");
     }
     switch ($record->val('file_format')) {
         case 'CSV':
         case 'XLS':
             $translationMemory = null;
             if ($record->val('target_translation_memory_uuid')) {
                 $translationMemory = XFTranslationMemory::loadTranslationMemoryByUuid($record->val('target_translation_memory_uuid'));
             }
             if ($record->val('file_format') === 'XLS') {
                 import('inc/ExcelStringImporter.php');
                 $importer = new ExcelStringImporter($filePath, $translationMemory);
             } else {
                 $importer = new CSVStringImporter($filePath, $translationMemory);
             }
             $importer->fixEncoding();
             $message = 'Import succeeded';
             $status = 'COMPLETE';
             try {
                 $importer->import();
             } catch (Exception $ex) {
                 $message = 'Import failed: ' . $ex->getMessage();
                 $status = 'FAILED';
             }
             $log = $message . "\r\n" . "Succeeded: " . $importer->succeeded . ", " . "Failed: " . $importer->failed . "\r\n" . "Error Log:\r\n===========\r\n";
             foreach ($importer->errors as $row) {
                 $log .= "Import Row: " . implode(",", $row['row']) . "\r\n" . "Error Message: " . $row['message'];
             }
             df_q(sprintf("update string_imports \n                            set \n                                log='%s', \n                                status='%s', \n                                succeeded=%d, \n                                failed=%d\n                            where\n                                string_import_id=%d", addslashes($log), addslashes($status), $importer->succeeded, $importer->failed, $record->val('string_import_id')));
             break;
         default:
             throw new Exception(sprintf("Unrecognized file format: %s", $record->val('file_format')));
     }
 }
Exemple #9
0
    /**
     * Sends the reset email to a particular user.
     * 
     * @param Dataface_Record $user The user record.
     * @return true on success
     *
     * @throws Exception code:  self::$EX_NO_USERNAME_FOR_USER If username is blank
     * @throws Exception code: self::$EX_NO_EMAIL_COLUMN_FOUND No email column was found in the users table.
     * @throws Exception code: self::$EX_NO_USERS_FOUND_WITH_EMAIL If the user record doesn't have an email address.
     */
    public function send_reset_email_for_user(Dataface_Record $user)
    {
        $app = Dataface_Application::getInstance();
        $auth = Dataface_AuthenticationTool::getInstance();
        $emailCol = $auth->getEmailColumn();
        $usernameCol = $auth->usernameColumn;
        if (!$emailCol) {
            throw new Exception(df_translate('actions.forgot_password.no_email_column_found', "No Email Column found in the users table.  Please specify one using the email_column directive in the [_auth] section of the conf.ini file."), self::$EX_NO_EMAIL_COLUMN_FOUND);
        }
        if (!$usernameCol) {
            throw new Exception(df_translate('actions.forgot_password.no_username_column_found', "No username column found in the users table. Please specify one using the username_column directive in the [_auth] section of the conf.ini file."), self::$EX_NO_USERNAME_COLUMN_FOUND);
        }
        if (!$user) {
            throw new Exception(df_translate('actions.forgot_password.null_user', "Cannot send email for null user"), self::$EX_NO_USERS_FOUND_WITH_EMAIL);
        }
        $username = $user->val($usernameCol);
        if (!$username) {
            throw new Exception(df_translate('actions.forgot_password.user_without_name', "Cannot reset password for user without a username"), self::$EX_NO_USERNAME_FOR_USER);
        }
        $email = $user->val($emailCol);
        if (!$email) {
            throw new Exception(df_translate('actions.forgot_password.user_without_email', "User has not email address on file"), $EX_NO_EMAIL_FOR_USER);
        }
        $ip = null;
        $val = ip2long($_SERVER['REMOTE_ADDR']);
        if ($val !== false) {
            $ip = sprintf('%u', $val);
        } else {
            $ip = 0;
            //If IP is empty MySQL throws Incorrect Integer value on insert
        }
        $expire_seconds = 600;
        if (@$app->_conf['reset_password_expiry']) {
            $expire_seconds = intval($app->_conf['reset_password_expiry']);
        }
        // Insert the entry
        $this->create_reset_password_table();
        $table = self::$TABLE_RESET_PASSWORD;
        $sql = "insert into `{$table}`\n\t\t\t(`request_uuid`, `username`, `request_ip`, `date_created`, `expires`)\n\t\t\tvalues\n\t\t\t(UUID(),'" . addslashes($username) . "','" . addslashes($ip) . "', NOW(), " . (time() + $expire_seconds) . ")";
        $res = xf_db_query($sql, df_db());
        if (!$res) {
            throw new Exception(xf_db_error(df_db()));
        }
        $id = xf_db_insert_id(df_db());
        $res = xf_db_query("select * from `{$table}` where request_id='" . addslashes($id) . "'", df_db());
        if (!$res) {
            throw new Exception(xf_db_error(df_db()));
        }
        $row = xf_db_fetch_assoc($res);
        if (!$row) {
            throw new Exception(df_translate('actions.forgot_password.failed_fetch_password_row', "Failed to fetch reset password request row from database after it has been inserted.  This should never happen ... must be a bug"));
        }
        $uuid = $row['request_uuid'];
        if (!$uuid) {
            throw new Exception(df_translate('actions.forgot_password.blank_uuid_for_reset_request', "Blank uuid for the reset request.  This should never happen.  Must be a bug."));
        }
        $url = df_absolute_url(DATAFACE_SITE_HREF . '?-action=forgot_password&--uuid=' . $uuid);
        $site_url = df_absolute_url(DATAFACE_SITE_URL);
        $msg = df_translate('actions.forgot_password.reset_password_request_email_body', <<<END
You have requested to reset the password for the user '{$username}'.
Please go to the URL below in order to proceed with resetting your password:
<{$url}>

If you did not make this request, please disregard this email.
END
, array('username' => $username, 'url' => $url));
        $subject = df_translate('actions.forgot_password.password_reset', "Password Reset");
        $del = $app->getDelegate();
        $info = array();
        if (isset($del) and method_exists($del, 'getResetPasswordEmailInfo')) {
            $info = $del->getResetPasswordEmailInfo($user, $url);
        }
        if (isset($info['subject'])) {
            $subject = $info['subject'];
        }
        if (isset($info['message'])) {
            $msg = $info['message'];
        }
        $parameters = null;
        if (isset($info['parameters'])) {
            $parameters = $info['parameters'];
        }
        $site_title = $app->getSiteTitle();
        $support_email = $_SERVER['SERVER_ADMIN'];
        if (isset($app->_conf['admin_email'])) {
            $support_email = $app->_conf['admin_email'];
        }
        if (isset($app->_conf['support_email'])) {
            $support_email = $app->_conf['support_email'];
        }
        $from_email = $support_email;
        if (strpos($support_email, '>') === false) {
            $from_email = $site_title . ' <' . $support_email . '>';
        }
        $headers = 'From: ' . $from_email . "\r\nReply-to: " . $from_email . "\r\nContent-type: text/plain; charset=" . $app->_conf['oe'];
        if (isset($info['headers'])) {
            $headers = $info['headers'];
        }
        //echo "Subject: $subject \nEmail: $email \n$msg \nHeaders: $headers";exit;
        if (@$app->_conf['_mail']['func']) {
            $func = $app->_conf['_mail']['func'];
        } else {
            $func = 'mail';
        }
        $res = $func($email, $subject, $msg, $headers, $parameters);
        if (!$res) {
            throw new Exception(df_translate('actions.forgot_password.failed_send_activation', "Failed to send activation email.  Please try again later."), DATAFACE_E_ERROR);
        } else {
            //echo "Successfully sent mail to $email";exit;
            return true;
        }
    }
Exemple #10
0
 /**
  * Gets an HTML diff output between the records at $id1 and $id2 
  * respectively, where $id1 and $id2 are history ids from the history__id
  * column of the history table.
  * @param string $tablename The name of the base table.
  * @param integer $id1 The id number of the first record (from the history__id column)
  * @param integer $id2 The id of the second record (from the history__id column)
  * @param string $fieldname Optional name of a field to return.
  * @returns mixed Either the value of the specified field name if $fieldname is specified,
  *			or a Dataface_Record object whose field values are formatted diffs.
  */
 function getDiffs($tablename, $id1, $id2 = null, $fieldname = null)
 {
     import('Text/Diff.php');
     import('Text/Diff/Renderer/inline.php');
     $htablename = $tablename . '__history';
     if (!Dataface_Table::tableExists($htablename)) {
         return PEAR::raiseError(df_translate('scripts.Dataface.HistoryTool.getDiffs.ERROR_HISTORY_TABLE_DOES_NOT_EXIST', "History table for '{$tablename}' does not exist, so we cannot obtain changes for records of that table.", array('tablename' => $tablename)), DATAFACE_E_ERROR);
     }
     $rec1 = df_get_record($htablename, array('history__id' => $id1));
     if (!isset($id2)) {
         // The 2nd id wasn't provided so we assume we want to know the diffs
         // against the current state of the record.
         $table =& Dataface_Table::loadTable($tablename);
         $query = $rec1->strvals(array_keys($table->keys()));
         $io = new Dataface_IO($tablename);
         $io->lang = $rec1->val('history__language');
         $rec2 = new Dataface_Record($tablename, array());
         $io->read($query, $rec2);
     } else {
         $rec2 = df_get_record($htablename, array('history__id' => $id2));
     }
     $vals1 = $rec1->strvals();
     $vals2 = $rec2->strvals();
     $vals_diff = array();
     $renderer = new Text_Diff_Renderer_inline();
     foreach ($vals2 as $key => $val) {
         $diff = new Text_Diff(explode("\n", @$vals1[$key]), explode("\n", $val));
         $vals_diff[$key] = $renderer->render($diff);
     }
     $diff_rec = new Dataface_Record($htablename, $vals_diff);
     if (isset($fieldname)) {
         return $diff_rec->val($fieldname);
     }
     return $diff_rec;
 }
 function normalized_translation_value__csvValue(Dataface_Record $record)
 {
     return $record->val('normalized_translation_value');
 }
Exemple #12
0
 /**
  * @brief Imports a node and all of its children into the database.
  *
  * @param stdClass $node The root node to import.
  * @param Dataface_Record $parentPage A record of the @e webpages table
  * that represents the parent page of the current page.
  *
  * @see SiteCrawler for more information about nodes and the properties
  * they can have.
  */
 public function importNode(stdClass $node, $parentPage = null)
 {
     $page = null;
     if (isset($node->path) and isset($node->httpStatus)) {
         $page = df_get_record('webpages', array('webpage_url' => '=' . $node->path, 'website_id' => '=' . $this->site->getRecord()->val('website_id')));
         if (!$page) {
             $page = new Dataface_Record('webpages', array());
             $page->setValues(array('website_id' => $this->site->getRecord()->val('website_id'), 'webpage_url' => $node->path, 'active' => -1, 'posted_by' => $this->username, 'parent_id' => $parentPage ? $parentPage->val('webpage_id') : null, 'is_loaded' => 0));
             $res = $page->save();
             if (PEAR::isError($res)) {
                 throw new Exception($res->getMessage());
             }
             $this->pagesAdded[] = $page;
         } else {
             $this->pagesUpdated[] = $page;
         }
         $page->setValues(array('last_checked' => date('Y-m-d H:i:s'), 'last_checked_response_code' => $node->httpStatus, 'last_checked_content_type' => $node->contentType, 'last_checked_by' => $this->username));
         $updateRefreshLog = false;
         $translationStats = array();
         //if ( $node->content and $this->loadContent and (!$page->val('locked') or $this->overrideLocks) ){
         if (@$node->content and @$this->loadContent) {
             if ($page->val('locked') and !$this->overrideLocks) {
                 error_log("Skipping refresh of " . @$node->path . " because the page is locked.");
             } else {
                 $page->setValues(array('last_refresh' => date('Y-m-d H:i:s'), 'last_refresh_response_code' => $node->httpStatus, 'is_loaded' => 1, 'webpage_content' => $node->content));
                 // Now log the check
                 $logEntry = new Dataface_Record('webpage_refresh_log', array());
                 $logEntry->setValues(array('webpage_id' => $page->val('webpage_id'), 'date_checked' => date('Y-m-d H:i:s'), 'response_code' => $node->httpStatus, 'content_type' => $node->contentType, 'content' => $node->content, 'checked_by' => $this->username));
                 $res = $logEntry->save();
                 if (PEAR::isError($res)) {
                     throw new Exception($res->getMessage());
                 }
                 if ($this->translate) {
                     $pageWrapper = new SweteWebpage($page);
                     $tmid = $pageWrapper->getTranslationMemoryId(true);
                     if ($tmid) {
                         $tm = $this->getTranslationMemory($tmid);
                         if ($tm) {
                             import('inc/PageProcessor.php');
                             $processor = new PageProcessor();
                             $processor->webpageRefreshLogId = $logEntry->val('refresh_log_id');
                             $processor->site = $this->site;
                             $processor->translationMemory = $tm;
                             $processor->page = $pageWrapper;
                             $processor->translateMinStatus = $this->translateMinStatus;
                             $processor->translateMaxStatus = $this->translateMaxStatus;
                             $processor->logTranslationMisses = $this->logTranslationMisses;
                             $processor->savePage = false;
                             $processor->saveTranslationLogRecord = true;
                             $processor->process();
                         }
                     }
                 }
             }
         }
         $res = $page->save();
         // Now log the check
         $logEntry = new Dataface_Record('webpage_check_log', array());
         $logEntry->setValues(array('webpage_id' => $page->val('webpage_id'), 'date_checked' => date('Y-m-d H:i:s'), 'response_code' => $node->httpStatus, 'content_type' => $node->contentType, 'checked_by' => $this->username));
         $res = $logEntry->save();
         if (PEAR::isError($res)) {
             throw new Exception($res->getMessage());
         }
     }
     if (isset($node->children) and is_array($node->children)) {
         foreach ($node->children as $child) {
             $this->importNode($child, $page);
         }
     }
 }
Exemple #13
0
    /**
     * Sends the reset email to a particular user.
     * 
     * @param Dataface_Record $user The user record.
     * @return true on success
     *
     * @throws Exception code:  self::$EX_NO_USERNAME_FOR_USER If username is blank
     * @throws Exception code: self::$EX_NO_EMAIL_COLUMN_FOUND No email column was found in the users table.
     * @throws Exception code: self::$EX_NO_USERS_FOUND_WITH_EMAIL If the user record doesn't have an email address.
     */
    public function send_reset_email_for_user(Dataface_Record $user)
    {
        $app = Dataface_Application::getInstance();
        $auth = Dataface_AuthenticationTool::getInstance();
        $emailCol = $auth->getEmailColumn();
        $usernameCol = $auth->usernameColumn;
        if (!$emailCol) {
            throw new Exception("No Email Column found in the users table.  Please specify one using the email_column directive in the [_auth] section of the conf.ini file.", self::$EX_NO_EMAIL_COLUMN_FOUND);
        }
        if (!$usernameCol) {
            throw new Exception("No username column found in the users table. Please specify one using the username_column directive in the [_auth] section of the conf.ini file.", self::$EX_NO_USERNAME_COLUMN_FOUND);
        }
        if (!$user) {
            throw new Exception("Cannot send email for null user", self::$EX_NO_USERS_FOUND_WITH_EMAIL);
        }
        $username = $user->val($usernameCol);
        if (!$username) {
            throw new Exception("Cannot reset password for user without a username", self::$EX_NO_USERNAME_FOR_USER);
        }
        $email = $user->val($emailCol);
        if (!$email) {
            throw new Exception("User has not email address on file", $EX_NO_EMAIL_FOR_USER);
        }
        $ip = null;
        $val = ip2long($_SERVER['REMOTE_ADDR']);
        if ($val !== false) {
            $ip = sprintf('%u', $val);
        }
        // Insert the entry
        $this->create_reset_password_table();
        $table = self::$TABLE_RESET_PASSWORD;
        $sql = "insert into `{$table}`\n\t\t\t(`request_uuid`, `username`, `request_ip`, `date_created`, `expires`)\n\t\t\tvalues\n\t\t\t(UUID(),'" . addslashes($username) . "','" . addslashes($ip) . "', NOW(), " . (time() + 600) . ")";
        $res = mysql_query($sql, df_db());
        if (!$res) {
            throw new Exception(mysql_error(df_db()));
        }
        $id = mysql_insert_id(df_db());
        $res = mysql_query("select * from `{$table}` where request_id='" . addslashes($id) . "'", df_db());
        if (!$res) {
            throw new Exception(mysql_error(df_db()));
        }
        $row = mysql_fetch_assoc($res);
        if (!$row) {
            throw new Exception("Failed to fetch reset password request row from database after it has been inserted.  This should never happen ... must be a bug");
        }
        $uuid = $row['request_uuid'];
        if (!$uuid) {
            throw new Exception("Blank uuid for the reset request.  This should never happen.  Must be a bug.");
        }
        $url = df_absolute_url(DATAFACE_SITE_HREF . '?-action=forgot_password&--uuid=' . $uuid);
        $site_url = df_absolute_url(DATAFACE_SITE_URL);
        $msg = <<<END
You have requested to reset the password for the user '{$username}'.
Please go to the URL below in order to proceed with resetting your password:
<{$url}>

If you did not make this request, please disregard this email.
END;
        $subject = 'Password Reset';
        $del = $app->getDelegate();
        $info = array();
        if (isset($del) and method_exists($del, 'getResetPasswordEmailInfo')) {
            $info = $del->getResetPasswordEmailInfo($user, $url);
        }
        if (isset($info['subject'])) {
            $subject = $info['subject'];
        }
        if (isset($info['message'])) {
            $msg = $info['message'];
        }
        $parameters = null;
        if (isset($info['parameters'])) {
            $parameters = $info['parameters'];
        }
        $site_title = $app->getSiteTitle();
        $support_email = $_SERVER['SERVER_ADMIN'];
        if (isset($app->_conf['admin_email'])) {
            $support_email = $app->_conf['admin_email'];
        }
        if (isset($app->_conf['support_email'])) {
            $support_email = $app->_conf['support_email'];
        }
        $headers = 'From: ' . $site_title . ' <' . $support_email . '>' . "\r\nReply-to: " . $site_title . " <" . $support_email . ">";
        if (isset($info['headers'])) {
            $headers = $info['headers'];
        }
        if (@$app->_conf['_mail']['func']) {
            $func = $app->_conf['_mail']['func'];
        } else {
            $func = 'mail';
        }
        $res = $func($email, $subject, $msg, $headers, $parameters);
        if (!$res) {
            throw new Exception('Failed to send activation email.  Please try again later.', DATAFACE_E_ERROR);
        } else {
            return true;
        }
    }
Exemple #14
0
 function testCompileStaticSite()
 {
     $siteRec = $this->staticSite;
     $job = SweteJob::createJob($this->staticSite);
     $this->assertFalse($job->getRecord()->val('compiled'), 'Job is not compiled yet but has compiled flag set.');
     //add webpage to static site
     $webpageContent = 'Test string 1';
     $pg = new Dataface_Record('webpages', array());
     $pg->lang = 'en';
     $pg->setValues(array('website_id' => $this->staticSite->getRecord()->val('website_id'), 'webpage_url' => 'index', 'webpage_content' => $webpageContent, 'active' => 1, 'posted_by' => 'test_user'));
     $res = $pg->save();
     if (PEAR::isError($res)) {
         throw new Exception($res->getMessage());
     }
     $pgid = $pg->val('webpage_id');
     $page1 = SweteWebpage::loadByUrl($this->staticSite->getRecord()->val('website_id'), 'index', 'en');
     $this->assertTrue($page1 instanceof SweteWebpage);
     //add webpage to job
     $job->addWebpage($page1);
     $this->assertTrue($job->containsWebpage($page1));
     $translatable = df_get_record('job_translatable', array('job_id' => '=' . $job->getRecord()->val('job_id')));
     $this->assertFalse($translatable);
     $job->compile();
     $res = df_q("select count(*) from job_translatable where job_id='" . addslashes($job->getRecord()->val('job_id')) . "'");
     list($num) = mysql_fetch_row($res);
     $this->assertEquals(1, $num, 'Should be one translatable created for job.');
     $translatable = df_get_record('job_translatable', array('job_id' => '=' . $job->getRecord()->val('job_id')));
     $this->assertTrue($translatable instanceof Dataface_Record, 'No translatable found for job.');
     $this->assertEquals($webpageContent, strip_tags($translatable->val('full_contents')));
     $job->refresh();
     $this->assertEquals(1, $job->getRecord()->val('compiled'), 'Job compiled flag is not set but should be');
 }