Beispiel #1
0
 protected function set_vars($event)
 {
     if (!is_object($event)) {
         return null;
     }
     if ($this->text) {
         $event->text = MPurifier::clean($this->text);
     } else {
         $event->text = null;
     }
     if ($this->start && MValidate::date($this->start)) {
         $event->start = $this->start;
     } else {
         return mapi_report_message('Not a valid start date.');
     }
     if ($this->end && MValidate::date($this->end)) {
         $event->end = $this->end;
     } else {
         return mapi_report_message('Not a valid end date.');
     }
     $start = new DateTime($event->start);
     $end = new DateTime($event->end);
     if (!$end > $start) {
         return mapi_report_message('Event end is before it\'s starting time.');
     }
     return true;
 }
Beispiel #2
0
function mapi_list_page_menus($id)
{
    if (!MValidate::id($id)) {
        return array();
    }
    return ORM::for_table('menus')->where_like('pages', '%{' . intval($id) . '}%')->find_many();
}
Beispiel #3
0
 protected function read($id)
 {
     if (!MValidate::id($id)) {
         return null;
     }
     $post = $this->read_record($id, $this->type);
     if ($post && $post->text) {
         $this->set_text($post->text);
     }
 }
 public function view($view = null, $data = null)
 {
     if (!$view || !MValidate::varname($view)) {
         $view = 'default';
     }
     $init = 'views:' . $view;
     $viewfile = mapi_abs_path($init, $this->get_wdir());
     if (is_file($viewfile) && is_readable($viewfile)) {
         include_once $viewfile;
     }
 }
Beispiel #5
0
 private static function get_ip()
 {
     $ip = null;
     if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
         $ip = $_SERVER['HTTP_CLIENT_IP'];
     } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
     } else {
         $ip = $_SERVER['REMOTE_ADDR'];
     }
     if (!MValidate::ip($ip)) {
         $ip = null;
     }
     self::$visitor['ip'] = $ip;
 }
Beispiel #6
0
 static function geocode($address = null)
 {
     $result = array('status' => 'FAIL', 'lat' => null, 'lng' => null);
     if (!MValidate::address($address)) {
         return $result;
     }
     global $geocoder;
     try {
         $geocode = $geocoder->geocode($address);
         $result['status'] = 'OK';
         $result['lat'] = $geocode->getLatitude();
         $result['lng'] = $geocode->getLongitude();
     } catch (Exception $e) {
         return $result;
     }
     return $result;
 }
 private function setup_object($preference)
 {
     if (!$preference || !is_object($preference)) {
         return null;
     }
     if ($this->name && MValidate::pref_name($this->name)) {
         $preference->name = $this->name;
     } else {
         return null;
     }
     if ($this->value && MValidate::pref_value($this->value)) {
         $preference->value = $this->value;
     } else {
         return null;
     }
     return true;
 }
Beispiel #8
0
 protected function set_vars($post)
 {
     if (!$post || !is_object($post)) {
         return null;
     }
     if ($this->text) {
         $post->text = MPurifier::clean($this->text);
     } else {
         $this->text = '';
     }
     if ($this->url && MValidate::url($this->url)) {
         $post->url = urlencode($this->url);
     } else {
         return mapi_report_message('Not a valid url.');
     }
     return true;
 }
Beispiel #9
0
function mwidget_map($zoom = 9, $cat_id = null)
{
    global $content;
    global $coords;
    if (MValidate::coord($coords['lat']) && MValidate::coord($coords['lng'])) {
        ?>
						<div id="mmap" style="width: 100%; height: 100%;"></div>
	                	<script>
	                        	var mmap = new MMap();
	                        	mmap.set_lat( <?php 
        MPut::_numeric($coords['lat']);
        ?>
 );
	                        	mmap.set_lng( <?php 
        MPut::_numeric($coords['lng']);
        ?>
 );
	                        	mmap.set_zoom( <?php 
        MPut::_numeric($zoom);
        ?>
 );
	                        	mmap.create_map( 'mmap' );
	                        	<?php 
        if ($content) {
            ?>
	                        			mmap.create_marker();
	                        	<?php 
        }
        ?>


					mmap.address_search();

	                        	var mmap_control = new MMapControl( mmap );
	                        	<?php 
        if ($cat_id) {
            echo 'mmap_control.auto_on( ' . intval($cat_id) . ' );';
        }
        ?>

	                	</script>
					<div id="mmap_modal" class="modal fade">
							  	<div class="modal-dialog">
							    		<div class="modal-content">
Beispiel #10
0
 public function __construct()
 {
     MMessaging::init();
     $SysConf = new MSettings();
     if (is_array($SysConf::$coords)) {
         global $coords;
         $coords['lat'] = $SysConf::$coords['lat'];
         $coords['lng'] = $SysConf::$coords['lng'];
     } elseif (isset($SysConf::$location)) {
         if (MValidate::address($SysConf::$location)) {
             global $geocoder;
             global $coords;
             try {
                 $geocode = $geocoder->geocode($SysConf::$location);
                 $coords['lat'] = $geocode->getLatitude();
                 $coords['lng'] = $geocode->getLongitude();
             } catch (Exception $e) {
             }
         }
     } else {
         if (MValidate::address(MSettings::$location)) {
             global $geocoder;
             global $coords;
             try {
                 $geocode = $geocoder->geocode(MSettings::$location);
                 $coords['lat'] = $geocode->getLatitude();
                 $coords['lng'] = $geocode->getLongitude();
             } catch (Exception $e) {
             }
         }
     }
     $routing = new M_Route();
     $module = new M_Module();
     $module_instance = $module->instance($routing->get_module(), $routing->get_task(), $routing->get_object());
     $template = new M_Template();
     $template_instance = $template->instance($module_instance);
 }
Beispiel #11
0
 /**
  * @return stdClass
  * 
  * Returns a stdClass object with:
  * stdClass->error	(an error array for each config name; empty if no errors)
  * stdClass->data   (an MDO object with the fetched data)
  * 
  */
 public function request()
 {
     $obj = MDO::instance();
     $err = array();
     foreach ($this->defaults as $config) {
         $name = $config[0];
         $default = $config[1];
         $request = isset($config[2]) ? $config[2] : "clean";
         $validate = isset($config[3]) ? $config[3] : null;
         $value = MRequest::_($request, $name, $default);
         if ($validate) {
             $valid = MValidate::_($validate, $value);
             if (!$valid) {
                 $err[$name] = MText::_("validate_" . $validate);
             }
         }
         $obj->set($name, $value);
     }
     //EOF foreach
     $return = new stdClass();
     $return->error = $err;
     $return->data = $obj;
     return $return;
 }
Beispiel #12
0
 function chmod()
 {
     if (!MRights::can("chmod")) {
         $this->popupError("chmod");
         return;
     }
     $mode = MRequest::int('chmod', null);
     if (!$mode) {
         $error = MText::_("no_mode_set");
         $this->view->add2Content('<script noCache="1">newDarkenPopup(\'error\',mText.error,\'' . $error . '\',500,250);</script>');
         $this->view->add2Content(fmGetFiles());
         return false;
     }
     $this->view->add2Content('<div style="display:none;">' . md5(uniqid()) . '</div>');
     $selectedFiles = $_REQUEST["selectedFiles"];
     $error = null;
     foreach ($selectedFiles as $selectedFile) {
         $selectedFile = _START_FOLDER . urldecode($selectedFile);
         $selectedFile = MValidate::path($selectedFile);
         $info = MFile::info($selectedFile);
         $status = MFile::chmod($selectedFile, $mode);
         if (!$status) {
             $error .= "File: <b>" . $info->baseName . "</b> " . MText::_("mode_cannot_change") . "<br>";
         }
     }
     if ($error) {
         $this->view->add2Content('<script noCache="1">newDarkenPopup(\'error\',mText.error,\'' . $error . '\',500,250);</script>');
     }
     $this->view->add2Content(fmGetFiles());
 }
Beispiel #13
0
 private static function send_notification($user)
 {
     $body = "";
     $body .= "New registration at " . MSettings::$domain . "\n\n";
     $body .= "User details:\n";
     $body .= "-username: "******"\n";
     $body .= "-name: " . $user->get_name() . "\n";
     $body .= "-email: " . $user->get_email() . "\n";
     $body .= ".\n\n";
     $body .= "Sincerely\n";
     $body .= MSettings::$domain;
     if (MValidate::email(MSettings::$reg_email)) {
         $from = MSettings::$reg_email;
     } else {
         return null;
     }
     if (MValidate::email(MObject::get('preference', 'website_email')->get_value())) {
         $to = MObject::get('preference', 'website_email')->get_value();
     } else {
         return null;
     }
     $message = Swift_Message::newInstance();
     $message->setSubject('New registration at ' . MSettings::$sitename);
     $message->setFrom(array($from));
     $message->setTo(array($to));
     $message->setBody($body);
     $transport = Swift_SmtpTransport::newInstance(MSettings::$reg_email_host, 25)->setUsername(MSettings::$reg_email_user)->setPassword(MSettings::$reg_email_pass);
     $mailer = Swift_Mailer::newInstance($transport);
     $mailer->send($message);
 }
Beispiel #14
0
 private function setup_object($user, $newuser = false)
 {
     if (!$user || !is_object($user)) {
         return null;
     }
     if ($this->group_id && MValidate::id($this->group_id)) {
         $user->group_id = $this->group_id;
     } else {
         return mapi_report_message('Not a valid group.');
     }
     if ($this->username && MValidate::username($this->username)) {
         $user->username = $this->username;
     } else {
         return mapi_report_message('Not a valid username.');
     }
     if (!$newuser) {
         if (!mapi_check_double('users', 'username', $this->username)) {
             return mapi_report_message('Username not available.');
         }
     }
     if ($this->email && MValidate::email($this->email)) {
         $user->email = $this->email;
     } else {
         return mapi_report_message('Not a valid email address.');
     }
     if ($this->name && MValidate::title($this->name)) {
         $user->name = $this->name;
     } else {
         return mapi_report_message('Not a valid name.');
     }
     if ($this->enabled && 1 == $this->enabled) {
         $user->enabled = 1;
     } else {
         $user->enabled = 0;
     }
     return true;
 }
Beispiel #15
0
 public function majax()
 {
     if (!MValidate::is_ajax()) {
         die;
     }
 }
Beispiel #16
0
 private function check_for_existing()
 {
     if (!isset($this->tables[$this->external]) || !MValidate::id($this->external_id)) {
         return false;
     }
     if (!MValidate::meta_name($this->name)) {
         return false;
     }
     $meta = ORM::for_table($this->tables[$this->external])->where('external_id', intval($this->external_id))->where('name', $this->name)->find_one();
     return $meta;
 }
Beispiel #17
0
 static function add_media($id)
 {
     $upload = MGet::file();
     if (!$upload) {
         return null;
     }
     if (!isset($upload['name'])) {
         return null;
     }
     if (!isset($upload['size'])) {
         return null;
     }
     if (!isset($upload['tmp'])) {
         return null;
     }
     if (!MValidate::mime_type($upload['tmp'], 'image')) {
         return null;
     }
     if (!MValidate::file_size($upload['size'])) {
         return null;
     }
     $title = null;
     $name_array = explode('.', $upload['name']);
     if (isset($name_array[0]) && strlen($name_array[0]) > 0) {
         if (MValidate::title($name_array[0])) {
             $title = $name_array[0];
         }
     }
     $mapi_url = mapi_url_current();
     $url = '';
     if (isset($mapi_url['host']) && strlen($mapi_url['host']) > 0) {
         $url .= $mapi_url['protocol'] . '://';
         $url .= $mapi_url['host'];
         if ('80' != $mapi_url['port']) {
             $url .= ':' . $mapi_url['port'];
         }
         $url .= str_replace('manager', 'media', RPATH);
         $url .= '/contents/';
         $url .= sha1_file($upload['tmp']) . '_' . $upload['name'];
     }
     if (!strlen($url) > 0) {
         return null;
     }
     $upload['path'] = APATH . '/media/contents/' . sha1_file($upload['tmp']) . '_' . $upload['name'];
     if (!move_uploaded_file($upload['tmp'], $upload['path'])) {
         return null;
     }
     $content = self::get_content($id);
     if ($content) {
         $img = ORM::for_table('content_media')->create();
         $img->external_id = $id;
         $img->title = $title;
         $img->url = $url;
         $img->save();
     }
 }
Beispiel #18
0
 private function setup_object($page, $newpage = false)
 {
     if (!$page || !is_object($page)) {
         return null;
     }
     if ($this->title && MValidate::title($this->title)) {
         $page->title = $this->title;
     } else {
         echo $this->title;
         return mapi_report_message('Not a valid page title.');
     }
     $page->name = $this->name;
     if ($newpage) {
         if (!mapi_check_double('pages', 'name', $this->name)) {
             return mapi_report_message('Page with that name already exists.');
         }
     }
     if (in_array($this->type, $this->types)) {
         $page->type = $this->type;
     } else {
         $page->type = 'url';
     }
     if ($this->url && MValidate::url($this->url)) {
         $page->url = $this->url;
     } else {
         return mapi_report_message('Not a valid url.');
     }
     if ($this->blank && 1 == $this->blank) {
         $page->blank = 1;
     } else {
         $page->blank = 0;
     }
     if ($this->enabled && 1 == $this->enabled) {
         $page->enabled = 1;
     } else {
         $page->enabled = 0;
     }
     return true;
 }
 static function ip($value)
 {
     if (!MValidate::string($value)) {
         return false;
     }
     $segments = explode('.', $value);
     if (sizeof($segments) != 4) {
         return false;
     }
     if ($segments[0][0] == '0') {
         return false;
     }
     foreach ($segments as $segment) {
         if ($segment == '' || strlen($segment) > 3) {
             return false;
         }
         if (preg_match('/[^0-9]/', $segment)) {
             return false;
         }
         if ($segment > 255) {
             return false;
         }
     }
     return true;
 }
 static function check_widget($widget)
 {
     if (!MValidate::ext_name($widget)) {
         return false;
     }
     if (!mapi_include_abs_path($widget, 'widgets/' . $widget)) {
         return false;
     }
     $widget_function = 'mwidget_' . strtolower($widget);
     if (!function_exists($widget_function)) {
         return false;
     }
     $markdown = self::markdown('widget', $widget);
     if (!isset($markdown['title']) || !strlen($markdown['title']) > 1) {
         return false;
     }
     if (!isset($markdown['version']) || !strlen($markdown['version']) > 0) {
         return false;
     }
     return true;
 }
 private function setup_object($category, $new = false)
 {
     if (!$category || !is_object($category)) {
         return null;
     }
     if ($this->title && MValidate::title($this->title)) {
         $category->title = $this->title;
     } else {
         return mapi_report_message('Not a valid category title: ' . $this->title);
     }
     $category->name = $this->name;
     if ($new) {
         if (!mapi_check_double('categories', 'name', $this->name)) {
             return mapi_report_message('Category with that name already exists: ' . $this->name);
         }
     }
     $category->contents = $this->save_contents();
     if ($this->flagship) {
         if (MValidate::id($this->flagship)) {
             $category->flagship = $this->flagship;
         } else {
             return mapi_report_message('Not a valid flagship product.');
         }
     }
     if ($this->enabled && 1 == $this->enabled) {
         $category->enabled = 1;
     } else {
         $category->enabled = 0;
     }
     return true;
 }
Beispiel #22
0
 private function setup_object($menu, $newmenu)
 {
     if (!$menu || !is_object($menu)) {
         return null;
     }
     if ($this->title && MValidate::title($this->title)) {
         $menu->title = $this->title;
     } else {
         return mapi_report_message('Not a valid title.');
     }
     $menu->name = $this->name;
     if ($newmenu) {
         if (!mapi_check_double('menus', 'name', $this->name)) {
             return mapi_report_message('Menu with that name already exists.');
         }
     }
     $menu->pages = $this->save_pages();
     if ($this->enabled && 1 == $this->enabled) {
         $menu->enabled = 1;
     } else {
         $menu->enabled = 0;
     }
     return true;
 }
 protected function valid($extension)
 {
     $this->set_type();
     if (!$extension) {
         return false;
     }
     if (!MValidate::ext_name($extension)) {
         return false;
     }
     if (!in_array($extension, $this->get_availables())) {
         return false;
     }
     return true;
 }
 private function setup_object($record, $new = false)
 {
     if (!$record || !is_object($record)) {
         return null;
     }
     if ($this->title && MValidate::title($this->title)) {
         $record->title = $this->title;
     } else {
         return mapi_report_message('Not a valid content title: ' . $this->title);
     }
     if ($this->license && MValidate::id($this->license) && in_array($this->license, mapi_available_ids('licenses'))) {
         $record->license = $this->license;
     } else {
         return mapi_report_message('Not a valid content license: ' . $this->license);
     }
     $record->name = $this->name;
     if ($new) {
         if (!mapi_check_double('contents', 'name', $this->name)) {
             return mapi_report_message('Content with that name already exists: ' . $this->name);
         }
     }
     if ($this->address && MValidate::address($this->address)) {
         $record->address = $this->address;
     } else {
         return mapi_report_message('Not a valid content address: ' . $this->address);
     }
     if (isset($this->meta_name)) {
         if ($this->meta_name && MValidate::meta_name($this->meta_name)) {
             $record->meta_name = $this->meta_name;
         } else {
             return mapi_report_message('Not a valid meta name: ' . $this->meta_name);
         }
     }
     if (isset($this->meta_value)) {
         if ($this->meta_value && MValidate::meta_value($this->meta_value)) {
             $record->meta_value = $this->meta_value;
         } else {
             return mapi_report_message('Not a valid meta value: ' . $this->meta_value);
         }
     }
     if ($this->lat && MValidate::coord($this->lat)) {
         $record->lat = $this->lat;
     } else {
         return mapi_report_message('Not a valid latitude.');
     }
     if ($this->lng && MValidate::coord($this->lng)) {
         $record->lng = $this->lng;
     } else {
         return mapi_report_message('Not a valid longitude.');
     }
     if ($this->hits && $this->hits > 0) {
         $record->hits = intval($this->hits);
     }
     if ($this->parent) {
         $record->parent = intval($this->parent);
     }
     if ($this->language) {
         $record->language = strval($this->language);
     }
     if ($this->translation && 1 == $this->translation) {
         $record->translation = 1;
     }
     if ($this->enabled && 1 == $this->enabled) {
         $record->enabled = 1;
     } else {
         $record->enabled = 0;
     }
     return true;
 }