Exemple #1
0
 public static function init()
 {
     if (self::$lang === null) {
         self::$lang = conf_get('cms.lang', 'en');
     }
     if (self::$data === null) {
         self::$data = array();
         $dir = new DirectoryIterator(CMS . 'locales');
         foreach ($dir as $fileInfo) {
             if (!$fileInfo->isDot() && !$fileInfo->isDir() && preg_match('/^(?:[a-zA-Z0-9_\\-]+)\\.([a-z]+)\\.php$/', $fileInfo->getFileName(), $mt)) {
                 if (!array_key_exists($mt[1], self::$data)) {
                     self::$data[$mt[1]] = array();
                 }
                 self::$data[$mt[1]] += (require_once $fileInfo->getPathName());
             }
         }
     }
 }
 protected function send_mail_smtp($from_email, $from, $to, $subject, $hdr, $body)
 {
     $host = (conf_get('mail.smtp.ssl') ? 'ssl://' : '') . conf_get('mail.smtp.host');
     $sock = fsockopen($host, conf_get('mail.smtp.port'), $errno, $errstr, conf_get('mail.smtp.timeout'));
     if (!$sock) {
         return "SMTP: {$errstr} ({$errno})";
     }
     $this->get_smtp_response($sock);
     // get dummy response
     $hostname = _SERVER('SERVER_NAME', 'localhost');
     $this->smtp_puts($sock, 'EHLO ' . $hostname . "\r\n");
     if ($this->get_smtp_response_code($sock) != 250) {
         $this->smtp_puts($sock, 'HELO ' . $hostname . "\r\n");
         if ($this->get_smtp_response_code($sock) != 250) {
             fclose($sock);
             return 'SMTP: error while sending HELO request';
         }
     }
     if (strlen(conf_get('mail.smtp.user'))) {
         $this->smtp_puts($sock, "AUTH LOGIN\r\n");
         if ($this->get_smtp_response_code($sock) != 334) {
             fclose($sock);
             return 'SMTP: error while senging AUTH LOGIN request';
         }
         $this->smtp_puts($sock, base64_encode(conf_get('mail.smtp.user')) . "\r\n");
         if ($this->get_smtp_response_code($sock) != 334) {
             fclose($sock);
             return 'SMTP: error while senging AUTH LOGIN request (username not accepted)';
         }
         $this->smtp_puts($sock, base64_encode(conf_get('mail.smtp.pass')) . "\r\n");
         if ($this->get_smtp_response_code($sock) != 235) {
             fclose($sock);
             return 'SMTP: error while senging AUTH LOGIN request (invalid password)';
         }
     }
     $this->smtp_puts($sock, 'MAIL FROM: <' . $from_email . ">\r\n");
     if ($this->get_smtp_response_code($sock) != 250) {
         fclose($sock);
         return 'SMTP: error while senging MAIL FROM request';
     }
     $this->smtp_puts($sock, 'RCPT TO: <' . $to . ">\r\n");
     $code = $this->get_smtp_response_code($sock);
     if ($code != 250 && $code != 251) {
         fclose($sock);
         return 'SMTP: error while senging RCPT TO request';
     }
     $this->smtp_puts($sock, "DATA\r\n");
     if ($this->get_smtp_response_code($sock) != 354) {
         fclose($sock);
         return 'SMTP: error while senging DATA request';
     }
     $hdr .= 'Subject: ' . $subject . "\r\n";
     $hdr .= "\r\n";
     $this->send_smtp_data($sock, $hdr, true);
     $this->send_smtp_data($sock, $body, false);
     $this->smtp_puts($sock, "\r\n.\r\n");
     if ($this->get_smtp_response_code($sock) != 250) {
         fclose($sock);
         return 'SMTP: error while senging DATA request (data not accepted)';
     }
     $this->smtp_puts($sock, "QUIT\r\n");
     if ($this->get_smtp_response_code($sock) != 221) {
         fclose($sock);
         return 'SMTP: error while senging QUIT request';
     }
     fclose($sock);
     return '';
 }
 protected function install($module)
 {
     $node = Node::get_node('site');
     if (!$node) {
         $this->message('Creating root node');
         Node::create_node(Node::Folder, 'site', conf_get('sitename'), Node::Visible | Node::System);
     } else {
         $this->message('Updating root node');
         $node->title = conf_get('sitename');
         $node->save();
     }
     if ($module) {
         $this->call_module_method($module, 'module_install', 'Installing');
         return;
     }
     if (!($dh = opendir(CMS . 'modules/'))) {
         $this->message('"' . CMS . 'modules/" not found');
         return;
     }
     $avail_modules = array();
     while (($module = readdir($dh)) !== false) {
         if (!is_dir(CMS . "modules/{$module}") || !is_readable(CMS . "modules/{$module}/admin.php")) {
             continue;
         }
         require_once CMS . "modules/{$module}/admin.php";
         $class_name = Cms::capitalize_words($module) . 'AdminModule';
         if (!is_callable(array($class_name, 'module_install'))) {
             continue;
         }
         $before = array();
         $after = array();
         if (is_callable(array($class_name, '_before'))) {
             $before = call_user_func(array($class_name, '_before'));
             if (!is_array($before)) {
                 $before = array($before);
             }
         }
         if (is_callable(array($class_name, '_after'))) {
             $after = call_user_func(array($class_name, '_after'));
             if (!is_array($after)) {
                 $after = array($after);
             }
         }
         $avail_modules[$module] = array('class' => $class_name, 'before' => $before, 'after' => $after);
     }
     closedir($dh);
     foreach ($avail_modules as $mod_name => $item) {
         foreach ($item['after'] as $name) {
             if (!array_key_exists($name, $avail_modules)) {
                 $this->message("\"{$mod_name}\" depends on \"{$name}\", but \"{$name}\" not found");
                 return;
             }
         }
     }
     foreach ($avail_modules as $mod_name => $item) {
         foreach ($item['before'] as $name) {
             if (array_key_exists($name, $avail_modules)) {
                 if (!in_array($mod_name, $avail_modules[$name]['after'])) {
                     $avail_modules[$name]['after'][] = $mod_name;
                 }
             }
         }
     }
     $modules_list = array();
     $modules_hash = array();
     for (;;) {
         $has_changes = false;
         $has_modules = false;
         foreach ($avail_modules as $mod_name => $item) {
             if (array_key_exists($mod_name, $modules_hash)) {
                 continue;
             }
             $has_modules = true;
             $can_insert = true;
             foreach ($item['after'] as $name) {
                 if (!array_key_exists($name, $modules_hash)) {
                     $can_insert = false;
                     break;
                 }
             }
             if (!$can_insert) {
                 continue;
             }
             $class_name = $item['class'];
             $modules_hash[$mod_name] = true;
             $modules_list[] = $mod_name;
             $has_changes = true;
         }
         if (!$has_modules) {
             break;
         }
         if (!$has_changes) {
             $this->message("Can't resolve modules dependencies");
             return;
         }
     }
     foreach ($modules_list as $module) {
         $this->call_module_method($module, 'module_install', 'Installing');
     }
 }
Exemple #4
0
/**
 * Saves upload files from their temporal path to the configured one
 *
 * @author Basilio Briceno <*****@*****.**>
 * @license http://www.gnu.org/licenses/lgpl.html GNU LGPL
 * @param string $input_name If not set it will try to save everything in _FILES
 * @param array $filter_rule Example: type => pdf, size => 1024
 * @return boolean Returns TRUE if file saved, FALSE if error
 */
function tf_fileup_save($input_name = 'all', $filter_rule = false)
{
    $path = realpath('.') . '/' . conf_get('default', 'uploads');
    // check if _FILES contains an element
    if (count($_FILES) < 1) {
        tf_error('[Upload] No files to save');
        return false;
    } else {
        // save everything in _FILES
        if ($input_name == 'all') {
            foreach ($_FILES as $key => $file) {
                // check file size
                if ($file['size'] > 1) {
                    $save_flag = true;
                    if ($filter_rule) {
                        $save_flag = tf_fileup_filter($key, $filter_rule);
                    }
                    if ($save_flag) {
                        // try to copy file to destination
                        if (!@copy($file['tmp_name'], $path . $file['name'])) {
                            tf_error('[Upload] Cannot write (' . $input_name . ') into ' . $path);
                        }
                        tf_log('Upload: File (' . $file['name'] . ') written into ' . $path);
                    }
                    unset($save_flag);
                }
            }
        }
        // check file existance
        if (!isset($_FILES[$input_name])) {
            tf_error('[Upload] Required input (' . $input_name . ') not found');
            return false;
        } else {
            // check file size
            if ($_FILES[$input_name]['size'] > 1) {
                $save_flag = true;
                if ($filter_rule) {
                    $save_flag = tf_fileup_filter($input_name, $filter_rule);
                }
                if ($save_flag) {
                    // try to copy file to destination
                    if (!@copy($_FILES[$input_name]['tmp_name'], $path . $_FILES[$input_name]['name'])) {
                        tf_error('[Upload] Cannot write (' . $input_name . ') into ' . $path);
                        return false;
                    }
                    tf_log('Upload: File (' . $_FILES[$input_name]['name'] . ') written into ' . $path);
                    return true;
                } else {
                    return false;
                }
                unset($save_flag);
            }
        }
    }
}