Example #1
0
 /**
  * Send an external email message
  * Caution! gmail may rewrite the "From" header unless you have added the address to your account.
  *
  * @param Tree   $tree
  * @param string $to_email
  * @param string $to_name
  * @param string $replyto_email
  * @param string $replyto_name
  * @param string $subject
  * @param string $message
  *
  * @return bool
  */
 public static function send(Tree $tree, $to_email, $to_name, $replyto_email, $replyto_name, $subject, $message)
 {
     try {
         $mail = new Zend_Mail('UTF-8');
         $mail->setSubject($subject)->setBodyHtml($message)->setBodyText(Filter::unescapeHtml($message))->setFrom(Site::getPreference('SMTP_FROM_NAME'), $tree->getPreference('title'))->addTo($to_email, $to_name)->setReplyTo($replyto_email, $replyto_name)->send(self::transport());
     } catch (\Exception $ex) {
         Log::addErrorLog('Mail: ' . $ex->getMessage());
         return false;
     }
     return true;
 }
Example #2
0
 /**
  * Send an external email message
  * Caution! gmail may rewrite the "From" header unless you have added the address to your account.
  *
  * @param Tree   $tree
  * @param string $to_email
  * @param string $to_name
  * @param string $replyto_email
  * @param string $replyto_name
  * @param string $subject
  * @param string $message
  *
  * @return bool
  */
 public static function send(Tree $tree, $to_email, $to_name, $replyto_email, $replyto_name, $subject, $message)
 {
     try {
         $mail = Swift_Message::newInstance()->setSubject($subject)->setFrom(Site::getPreference('SMTP_FROM_NAME'), $tree->getPreference('title'))->setTo($to_email, $to_name)->setReplyTo($replyto_email, $replyto_name)->setBody($message, 'text/html')->addPart(Filter::unescapeHtml($message), 'text/plain');
         Swift_Mailer::newInstance(self::transport())->send($mail);
     } catch (Exception $ex) {
         Log::addErrorLog('Mail: ' . $ex->getMessage());
         return false;
     }
     return true;
 }
Example #3
0
 /**
  * Task@setStatus
  */
 public function setStatus()
 {
     $controller = new JsonController();
     $task_name = Filter::get('task');
     $task = $this->provider->getTask($task_name, false);
     $controller->restrictAccess(true && Auth::isAdmin() && $task);
     $status = Filter::getBool('status');
     $res = array('task' => $task->getName(), 'error' => null);
     try {
         $this->provider->setTaskStatus($task, $status);
         $res['status'] = $status;
         Log::addConfigurationLog('Module ' . $this->module->getName() . ' : Admin Task "' . $task->getName() . '" has been ' . ($status ? 'enabled' : 'disabled') . '.');
     } catch (\Exception $ex) {
         $res['error'] = $ex->getMessage();
         Log::addErrorLog('Module ' . $this->module->getName() . ' : Admin Task "' . $task->getName() . '" could not be ' . ($status ? 'enabled' : 'disabled') . '. Error: ' . $ex->getMessage());
     }
     $controller->pageHeader();
     if ($res['error']) {
         http_response_code(500);
     }
     $controller->encode($res);
 }
Example #4
0
                $message['from_name'] = $from_name;
                $message['from_email'] = $from_email;
            }
            $message['subject'] = $subject;
            $message['body'] = nl2br($body, false);
            $message['created'] = WT_TIMESTAMP;
            $message['method'] = $method;
            $message['url'] = $url;
            if ($i > 0) {
                $message['no_from'] = true;
            }
            if (addMessage($message)) {
                FlashMessages::addMessage(I18N::translate('Message successfully sent to %s', Filter::escapeHtml($to)));
            } else {
                FlashMessages::addMessage(I18N::translate('Message was not sent'));
                Log::addErrorLog('Unable to send a message. FROM:' . $from . ' TO:' . $to . ' (failed to send)');
            }
            $i++;
        }
        $controller->pageHeader()->addInlineJavascript('window.opener.location.reload(); window.close();');
        break;
}
/**
 * Add a message to a user's inbox
 *
 * @param string[] $message
 *
 * @return bool
 */
function addMessage($message)
{
 /**
  * {@inheritDoc}
  * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface::saveConfig()
  */
 public function saveConfig()
 {
     try {
         foreach (Tree::getAll() as $tree) {
             if (Auth::isManager($tree)) {
                 $tree_enabled = Filter::postInteger('HEALTHCHECK_ENABLED_' . $tree->getTreeId(), 0, 1);
                 $tree->setPreference('MAJ_AT_' . $this->getName() . '_ENABLED', $tree_enabled);
             }
         }
         return true;
     } catch (\Exception $ex) {
         Log::addErrorLog(sprintf('Error while updating the Admin Task "%s". Exception: %s', $this->getName(), $ex->getMessage()));
         return false;
     }
 }
Example #6
0
 /**
  * imagettftext is the function that is most likely to throw an error
  * use this custom error handler to catch and log it
  *
  * @param int    $errno
  * @param string $errstr
  *
  * @return bool
  */
 function imageTtfTextErrorHandler($errno, $errstr)
 {
     // log the error
     Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<');
     // change value of useTTF to false so the fallback watermarking can be used.
     $this->use_ttf = false;
     return true;
 }
 /**
  * Replace variable identifiers with their values.
  *
  * @param string $expression An expression such as "$foo == 123"
  * @param bool   $quote      Whether to add quotation marks
  *
  * @return string
  */
 private function substituteVars($expression, $quote)
 {
     $that = $this;
     // PHP5.3 cannot access $this inside a closure
     return preg_replace_callback('/\\$(\\w+)/', function ($matches) use($that, $quote) {
         if (isset($that->vars[$matches[1]]['id'])) {
             if ($quote) {
                 return "'" . addcslashes($that->vars[$matches[1]]['id'], "'") . "'";
             } else {
                 return $that->vars[$matches[1]]['id'];
             }
         } else {
             Log::addErrorLog(sprintf('Undefined variable $%s in report', $matches[1]));
             return '$' . $matches[1];
         }
     }, $expression);
 }
Example #8
0
    public function getSidebarContent()
    {
        // code based on similar in function_print_list.php
        global $controller;
        // load the module stylesheet
        $html = $this->includeCss(WT_MODULES_DIR . $this->getName() . '/css/style.css') . '<script src="' . WT_STATIC_URL . $this->directory . '/js/sidebar.js" defer="defer"></script>';
        $controller->addInlineJavascript('
			jQuery("#' . $this->getName() . ' a").text("' . $this->getSidebarTitle() . '");
			jQuery("#' . $this->getName() . '_content").on("click", ".frl-area-title", function(e){
				e.preventDefault();
				jQuery(this).next(".frl-list").slideToggle()
				jQuery(this).parent().siblings().find(".frl-list").slideUp();
			});
		');
        try {
            $FRL_PLUGINS = unserialize($this->getSetting('FRL_PLUGINS'));
            $html .= '<ul id="fancy_research_links_content">';
            $i = 0;
            $total_enabled_plugins = 0;
            foreach ($this->module()->getPluginList() as $area => $plugins) {
                $enabled_plugins = $this->module()->countEnabledPlugins($plugins, $FRL_PLUGINS);
                $total_enabled_plugins = $total_enabled_plugins + $enabled_plugins;
                if ($enabled_plugins > 0) {
                    $html .= '<li class="frl-area"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span><a href="#" class="frl-area-title">' . $area . ' (' . $enabled_plugins . ')' . '</a>' . '<ul class="frl-list">';
                    $i++;
                    foreach ($plugins as $label => $plugin) {
                        if (is_array($FRL_PLUGINS) && array_key_exists($label, $FRL_PLUGINS)) {
                            $enabled = $FRL_PLUGINS[$label];
                        } else {
                            $enabled = '1';
                        }
                        if ($enabled) {
                            foreach ($controller->record->getFacts() as $fact) {
                                $tag = $fact->getTag();
                                if ($tag == "NAME") {
                                    $this->primary = $this->module()->getPrimaryName($fact);
                                    break;
                                    // only use the first fact with a NAME tag found.
                                }
                            }
                            if ($this->primary) {
                                if ($plugin->createLinkOnly()) {
                                    $link = $plugin->createLinkOnly();
                                } else {
                                    $this->attrs = array('birthyear' => $controller->record->getBirthYear(), 'birthplace' => $controller->record->getBirthPlace(), 'deathyear' => $controller->record->getDeathYear(), 'deathplace' => $controller->record->getDeathPlace());
                                    $link = $plugin->createLink($this->module()->getNames($this->primary, $this->attrs, $plugin->encodePlus()));
                                }
                                $html .= '<li>' . '<a href="' . Filter::escapeHtml($link) . '">' . $plugin->getPluginName() . '</a>' . '</li>';
                            }
                        }
                    }
                    $html .= '</ul>';
                }
            }
            $html .= '</ul>';
            if ($total_enabled_plugins === 0) {
                $html = I18N::translate('There are no research links available for this individual.');
            }
            return $html;
        } catch (\ErrorException $ex) {
            Log::addErrorLog('Fancy ResearchLinks: ' . $ex->getMessage());
            return I18N::translate('There are no research links available for this individual.');
        }
    }
Example #9
0
 /**
  * recursively find all of the csv files on the server
  *
  * @param string $path
  *
  * @return string[]
  */
 private function findFiles($path)
 {
     $placefiles = array();
     try {
         $di = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS);
         $it = new \RecursiveIteratorIterator($di);
         foreach ($it as $file) {
             if ($file->getExtension() == "csv") {
                 $placefiles[] = '/' . $file->getFilename();
             }
         }
     } catch (\Exception $e) {
         Log::addErrorLog(basename($e->getFile()) . ' - line: ' . $e->getLine() . ' - ' . $e->getMessage());
     }
     return $placefiles;
 }
Example #10
0
        $long_message .= '#' . $level . ' ' . $frame['file'] . ':' . $frame['line'] . ' ';
        $short_message .= '#' . $level . ' ' . $frame['file'] . ':' . $frame['line'] . ' ';
        if ($level) {
            $long_message .= $frame['function'] . '(' . implode(', ', $frame['args']) . ')' . PHP_EOL;
            $short_message .= $frame['function'] . "()<br>";
        } else {
            $long_message .= get_class($ex) . '("' . $ex->getMessage() . '")' . PHP_EOL;
            $short_message .= get_class($ex) . '("' . $ex->getMessage() . '")<br>';
        }
    }
    if (WT_DEBUG) {
        echo $long_message;
    } else {
        echo $short_message;
    }
    Log::addErrorLog($long_message);
});
// Load our configuration file, so we can connect to the database
if (file_exists(WT_ROOT . 'data/config.ini.php')) {
    $dbconfig = parse_ini_file(WT_ROOT . 'data/config.ini.php');
    // Invalid/unreadable config file?
    if (!is_array($dbconfig)) {
        header('Location: ' . WT_BASE_URL . 'site-unavailable.php');
        exit;
    }
    // Down for maintenance?
    if (file_exists(WT_ROOT . 'data/offline.txt')) {
        header('Location: ' . WT_BASE_URL . 'site-offline.php');
        exit;
    }
} else {
Example #11
0
 /**
  * {inhericDoc}
  * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::deleteTask()
  */
 public function deleteTask($task_name)
 {
     try {
         Database::beginTransaction();
         Database::prepare('DELETE FROM  `##maj_admintasks` WHERE majat_name= :task_name')->execute(array('task_name' => $task_name));
         Database::prepare('DELETE FROM  `##gedcom_setting` WHERE setting_name LIKE :setting_name')->execute(array('setting_name' => 'MAJ_AT_' . $task_name . '%'));
         Database::commit();
         Log::addConfigurationLog('Admin Task ' . $task_name . ' has been deleted from disk - deleting it from DB');
         return true;
     } catch (\Exception $ex) {
         Database::rollback();
         Log::addErrorLog('An error occurred while deleting Admin Task ' . $task_name . '. Exception: ' . $ex->getMessage());
         return false;
     }
 }
Example #12
0
 /**
  * {@inhericDoc}
  * @see \Fisharebest\Webtrees\GedcomRecord::getInstance()
  */
 public static function getInstance($xref, Tree $tree, $gedcom = null, CertificateProviderInterface $provider = null)
 {
     try {
         $certfile = Functions::decryptFromSafeBase64($xref);
         //NEED TO CHECK THAT !!!
         if (Functions::isValidPath($certfile, true)) {
             return new Certificate($certfile, $tree, $provider);
         }
     } catch (\Exception $ex) {
         Log::addErrorLog('Certificate module error : > ' . $ex->getMessage() . ' < with data > ' . $xref . ' <');
     }
     return null;
 }
 /**
  * GeoAnalysis@delete
  */
 public function delete()
 {
     global $WT_TREE;
     $controller = new JsonController();
     $ga_id = Filter::getInteger('ga_id');
     $ga = $this->provider->getGeoAnalysis($ga_id, false);
     $controller->restrictAccess(true && Auth::isManager($WT_TREE) && $ga);
     $res = array('geoanalysis' => $ga->getId(), 'error' => null);
     try {
         $this->provider->deleteGeoAnalysis($ga);
         Log::addConfigurationLog('Module ' . $this->module->getName() . ' : Geo Analysis ID "' . $ga->getId() . '" has been deleted.');
     } catch (\Exception $ex) {
         $res['error'] = $ex->getMessage();
         Log::addErrorLog('Module ' . $this->module->getName() . ' : Geo Analysis ID "' . $ga->getId() . '" could not be deleted. Error: ' . $ex->getMessage());
     }
     $controller->pageHeader();
     if ($res['error']) {
         http_response_code(500);
     }
     $controller->encode($res);
 }
Example #14
0
                    $arg = '[' . gettype($arg) . ']';
                    break;
            }
        });
        $frame['file'] = str_replace(dirname(__DIR__), '', $frame['file']);
        $message .= '#' . $level . ' ' . $frame['file'] . ':' . $frame['line'] . ' ';
        if ($level) {
            $message .= $frame['function'] . '(' . implode(', ', $frame['args']) . ')' . PHP_EOL;
        } else {
            $message .= get_class($ex) . '("' . $ex->getMessage() . '")' . PHP_EOL;
        }
    }
    if (true || error_reporting() & $ex->getCode()) {
        echo $message;
    }
    Log::addErrorLog($message);
});
// Load our configuration file, so we can connect to the database
if (file_exists(WT_ROOT . 'data/config.ini.php')) {
    $dbconfig = parse_ini_file(WT_ROOT . 'data/config.ini.php');
    // Invalid/unreadable config file?
    if (!is_array($dbconfig)) {
        header('Location: ' . WT_BASE_URL . 'site-unavailable.php');
        exit;
    }
    // Down for maintenance?
    if (file_exists(WT_ROOT . 'data/offline.txt')) {
        header('Location: ' . WT_BASE_URL . 'site-offline.php');
        exit;
    }
} else {
Example #15
0
/**
 * imagettftext is the function that is most likely to throw an error
 * use this custom error handler to catch and log it
 *
 * @param int    $errno
 * @param string $errstr
 *
 * @return bool
 */
function imagettftextErrorHandler($errno, $errstr)
{
    global $useTTF, $serverFilename;
    // log the error
    Log::addErrorLog('Media Firewall error: >' . $errno . '/' . $errstr . '< while processing file >' . $serverFilename . '<');
    // change value of useTTF to false so the fallback watermarking can be used.
    $useTTF = false;
    return true;
}
 /**
  * Update a geodispersion analysis in the database, in transactional manner.
  * When successful, returns the updated GeoAnalysis object
  *  
  * @param GeoAnalysis $ga
  * @return GeoAnalysis
  */
 public function updateGeoAnalysis(GeoAnalysis $ga)
 {
     try {
         Database::beginTransaction();
         Database::prepare('UPDATE `##maj_geodispersion`' . ' SET majgd_descr = :description,' . ' majgd_sublevel = :analysis_level,' . ' majgd_map = :map,' . ' majgd_toplevel = :map_top_level,' . ' majgd_useflagsgen = :use_flags,' . ' majgd_detailsgen = :gen_details' . ' WHERE majgd_file = :gedcom_id AND majgd_id = :ga_id')->execute(array('gedcom_id' => $this->tree->getTreeId(), 'ga_id' => $ga->getId(), 'description' => $ga->getTitle(), 'analysis_level' => $ga->getAnalysisLevel(), 'use_flags' => $ga->getOptions() && $ga->getOptions()->isUsingFlags() ? 'yes' : 'no', 'gen_details' => $ga->getOptions() ? $ga->getOptions()->getMaxDetailsInGen() : 0, 'map' => $ga->hasMap() ? $ga->getOptions()->getMap()->getFileName() : null, 'map_top_level' => $ga->hasMap() ? $ga->getOptions()->getMapLevel() : -100));
         $ga = $this->getGeoAnalysis($ga->getId(), false);
         Database::commit();
     } catch (\Exception $ex) {
         Database::rollback();
         Log::addErrorLog('The Geo Analysis ID “' . $ga->getId() . '” failed to be updated. Transaction rollbacked. Exception: ' . $ex->getMessage());
         $ga = null;
     }
     return $ga;
 }