Esempio n. 1
0
 /**
  * @return bool
  * @throws \Exception
  * @throws \Zend_Db_Table_Exception
  * @throws \Zend_Db_Table_Row_Exception
  */
 public function deleteImage()
 {
     if ($this->owner_id == $_SESSION['user']->userid && $this->owner_type === null) {
         $albums = new GalleryAlbums();
         $album = $albums->find($this->albumid);
         /** @noinspection PhpUndefinedMethodInspection */
         $album->current()->removeImage($this->id);
         $settings = Cunity::get("settings");
         $likes = new Likes();
         $comments = new Comments();
         $posts = new Posts();
         $posts->delete([$posts->getAdapter()->quote("type=`image`"), $posts->getAdapter()->quoteInto("content=?", $this->id)]);
         $comments->delete($this->_getTable()->getAdapter()->quoteInto("ref_id=? AND ref_name='image'", $this->id));
         $likes->delete($this->_getTable()->getAdapter()->quoteInto("ref_id=? AND ref_name='image'", $this->id));
         $filename = "../data/uploads/" . $settings->getSetting("core.filesdir") . "/" . $this->filename;
         $filenameThumb = "../data/uploads/" . $settings->getSetting("core.filesdir") . "/thumb_" . $this->filename;
         $filenameCr = "../data/uploads/" . $settings->getSetting("core.filesdir") . "/cr_" . $this->filename;
         if (file_exists($filename)) {
             unlink($filename);
         }
         if (file_exists($filenameThumb)) {
             unlink($filenameThumb);
         }
         if (file_exists($filenameCr)) {
             unlink($filenameCr);
         }
         return $this->delete() == 1;
     }
     return false;
 }
Esempio n. 2
0
 /**
  * @throws \Exception
  */
 private function loadData()
 {
     $modules = new \Cunity\Core\Models\Db\Table\Modules();
     $installedModules = $modules->getModules()->toArray();
     $config = \Cunity\Core\Cunity::get("config");
     $this->assignments['smtp_check'] = $config->mail->smtp_check;
     $this->assignments['modules'] = $installedModules;
 }
Esempio n. 3
0
 /**
  * @throws \Cunity\Core\Exception
  * @throws \Exception
  */
 public function __construct()
 {
     parent::__construct();
     $this->registerCss("events", "event");
     $this->registerCss("events", "event-edit");
     $this->registerScript("events", "event-edit");
     $this->assign("max_filesize", ini_get('upload_max_filesize'));
     $this->assign("upload_limit", Cunity::get("config")->site->upload_limit);
 }
Esempio n. 4
0
 /**
  *
  * @return String
  */
 public static function getDbprefix()
 {
     $dbprefix = '';
     $config = Cunity::get("config");
     if ($config->db->params->table_prefix !== '') {
         $dbprefix = $config->db->params->table_prefix . '_';
     }
     return $dbprefix;
 }
Esempio n. 5
0
 /**
  *
  */
 public function __construct()
 {
     if (array_key_exists('action', $_REQUEST) && $_REQUEST['type'] === 'ajax' && $_REQUEST['action'] != 'prepareDatabase') {
         \Cunity\Core\Cunity::init();
     } elseif (array_key_exists('action', $_REQUEST) && $_REQUEST['type'] != 'ajax') {
         $this->init();
     }
     $this->initTranslator();
     $this->handleRequest();
 }
Esempio n. 6
0
 /**
  *
  */
 public function __construct()
 {
     $this->loadData();
     $modules = new Modules();
     $installedModules = $modules->getModules()->toArray();
     $config = \Cunity\Core\Cunity::get("config");
     $this->assignments['smtp_check'] = $config->mail->smtp_check;
     $this->assignments['modules'] = $installedModules;
     $this->assignments['version'] = $config->site->version;
     $this->render("dashboard");
 }
Esempio n. 7
0
 /**
  * @return string
  */
 protected static function getRemoteVersion($force = false)
 {
     $settings = Cunity::get("settings");
     if ($settings->getSetting('core.lastupdatecheck') < mktime(0, 0, 1, date('m'), date('d'), date('Y')) || $force) {
         $context = array('http' => array('header' => 'Referer: ' . $settings->getSetting('core.siteurl')));
         $xcontext = stream_context_create($context);
         $settings->setSetting('core.remoteversion', file_get_contents(self::$UPDATECHECKURL, 'r', $xcontext));
         $settings->setSetting('core.lastupdatecheck', time());
     }
     return $settings->getSetting('core.remoteversion');
 }
Esempio n. 8
0
 /**
  *
  */
 public function __construct()
 {
     parent::__construct();
     $this->registerScript("profile", "profile-edit");
     $this->registerScript("profile", "profile");
     $this->registerCss("profile", "profile");
     $this->registerCss("profile", "profile-edit");
     $this->registerCunityPlugin("js", ["jquery-ui-1.10.4.custom.min.js"]);
     $this->registerCunityPlugin("summernote", ["css/summernote.css", "js/summernote.min.js"]);
     $this->assign("upload_limit", Cunity::get("config")->site->upload_limit);
 }
Esempio n. 9
0
 /**
  * @param $urlString
  * @return string
  * @throws \Exception
  */
 public static function convertUrl($urlString)
 {
     //if mod rewrite is enabled!
     if (Cunity::get("mod_rewrite")) {
         $parsedUrl = parse_url($urlString);
         parse_str($parsedUrl['query'], $parsedQuery);
         return Cunity::get("settings")->getSetting("core.siteurl") . implode('/', $parsedQuery);
     } else {
         return Cunity::get("settings")->getSetting("core.siteurl") . $urlString;
     }
 }
Esempio n. 10
0
 /**
  * @param array $receiver
  * @param array $content
  * @param array $cc
  * @throws \Exception
  */
 public function __construct(array $receiver = [], array $content = [], array $cc = [])
 {
     parent::__construct();
     if (empty($receiver)) {
         $settings = Cunity::get("settings");
         $receiver = ["email" => $settings->getSetting("core.contact_mail"), "name" => "Cunity Administrator"];
     }
     $this->_receiver = $receiver;
     $this->_cc = $cc;
     $this->_subject = $content['subject'];
     $this->assign('message', $content['message']);
     $this->show();
 }
Esempio n. 11
0
 /**
  * @throws \Exception
  */
 public function __construct()
 {
     View::initTranslator();
     array_walk_recursive($_GET, [$this, 'trimhtml']);
     array_walk_recursive($_POST, [$this, 'trimhtml']);
     Cunity::init();
     //use the filesdir hash as unique session name
     session_name("cunity-" . Cunity::get("settings")->getSetting("core.filesdir"));
     session_start();
     if (Models\Request::isAjaxRequest()) {
         set_exception_handler([$this, 'handleAjaxException']);
     } else {
         set_exception_handler([$this, 'handleException']);
     }
     $this->handleQuery();
 }
Esempio n. 12
0
 /**
  * @param mixed $value
  * @return bool
  * @throws \Exception
  */
 public function isValid($value)
 {
     $this->_setValue($value);
     if (!is_array($value) || empty($value['month']) || empty($value['day']) || empty($value['year'])) {
         $this->_error(self::INVALID);
     } elseif (!checkdate($value['month'], $value['day'], $value['year'])) {
         $this->_error(self::INVALID);
     } else {
         $now = new \DateTime();
         $received = new \DateTime($value['year'] . "-" . $value['month'] . "-" . $value['day']);
         if ($received->diff($now)->y < Cunity::get("settings")->getSetting("register.min_age")) {
             $this->_error(self::TOOYOUNG);
         } else {
             return true;
         }
     }
     return false;
 }
Esempio n. 13
0
 /**
  * @param array $data
  * @return bool
  * @throws \Exception
  */
 public function registerNewUser(array $data, $groupId = 0, $sendVerfificationMail = true)
 {
     $salt = Unique::createSalt(25);
     if (Cunity::get("settings")->getSetting("core.fullname")) {
         $name = $data['firstname'] . " " . $data['lastname'];
     } else {
         $name = $data['username'];
     }
     $result = $this->insert(["email" => trim($data['email']), "userhash" => $this->createUniqueHash(), "username" => $data['username'], "groupid" => $groupId, "password" => sha1(trim($data['password']) . $salt), "salt" => $salt, "name" => $name, "firstname" => $data['firstname'], "lastname" => $data['lastname']]);
     if (array_key_exists('field', $_POST)) {
         $profileFieldsUser = new ProfileFieldsUsers([], $this->search('userid', $result));
         $profileFieldsUser->update($_REQUEST['field'], '');
     }
     if ($result && $sendVerfificationMail) {
         new VerifyMail(["name" => $name, "email" => $data['email']], $salt);
         return true;
     }
     return false;
 }
Esempio n. 14
0
 /**
  * @return bool
  * @throws \Exception
  * @throws \Zend_Db_Table_Row_Exception
  */
 public function deleteAlbum()
 {
     $images = new GalleryImages();
     $imageslist = $images->getImages($this->id);
     $settings = Cunity::get("settings");
     foreach ($imageslist as $image) {
         $likes = new Likes();
         $comments = new Comments();
         $comments->delete($this->getTable()->getAdapter()->quoteInto("ref_id=? AND ref_name='image'", $image['id']));
         $likes->delete($this->getTable()->getAdapter()->quoteInto("ref_id=? AND ref_name='image'", $image['id']));
         unlink("../data/uploads/" . $settings->getSetting("core.filesdir") . "/" . $image['filename']);
         unlink("../data/uploads/" . $settings->getSetting("core.filesdir") . "/thumb_" . $image['filename']);
         if (file_exists("../data/uploads/" . $settings->getSetting("core.filesdir") . "/cr_" . $image['filename'])) {
             unlink("../data/uploads/" . $settings->getSetting("core.filesdir") . "/cr_" . $image['filename']);
         }
     }
     $images->delete($images->getAdapter()->quoteInto("albumid=?", $this->id));
     return 0 < $this->delete();
 }
Esempio n. 15
0
 /**
  * @return array
  */
 public function getMainMenu()
 {
     $res = $this->fetchAll($this->select()->where("menu='main'")->order("pos"));
     $menu = $res->toArray();
     $menus = [];
     foreach ($menu as $_menu) {
         if ($_menu['type'] === 'module') {
             Cunity::set('modules', new Modules());
             /** @var Modules $modules */
             $modules = Cunity::get('modules');
             $moduleName = $_menu['content'];
             $module = $modules->fetchRow('namespace = "' . $moduleName . '"')->toArray();
             if ($module['status'] == 1) {
                 $menus[] = $_menu;
             }
         }
     }
     return $menus;
 }
Esempio n. 16
0
 /**
  * @param string $status
  * @return Zend_Db_Expr
  * @throws \Exception
  */
 public static function getEventsListQuery($status = "> 0")
 {
     return new Zend_Db_Expr(Cunity::get("db")->select()->from(Mysqli::getDbprefix() . "events_guests", "eventid")->where("status" . $status)->where("userid=?", $_SESSION['user']->userid));
 }
Esempio n. 17
0
 /**
  * @throws \Exception
  */
 private function delete()
 {
     $config = Cunity::get("config");
     $functions = $config->registerFunctions->toArray();
     foreach ($functions["module"] as $module) {
         call_user_func(["Cunity\\" . ucfirst($module) . "\\Controller", "onUnregister"], $_SESSION['user']);
     }
 }
Esempio n. 18
0
 /**
  * @throws \Exception
  */
 protected function _setupTableName()
 {
     $this->_config = Cunity::get("config");
     if ($this->_config->db->params->table_prefix !== '') {
         $this->_dbprefix = $this->_config->db->params->table_prefix . '_';
     }
     $this->_name = $this->_dbprefix . $this->_name;
     parent::_setupTableName();
 }
Esempio n. 19
0
 /**
  * @param string $status
  * @return Zend_Db_Expr
  * @throws \Exception
  */
 public static function getFriendListQuery($status = "> 0")
 {
     return new Zend_Db_Expr(Cunity::get("db")->select()->from(Mysqli::getDbprefix() . "relations", new Zend_Db_Expr("(CASE WHEN sender = " . $_SESSION['user']->userid . " THEN receiver WHEN receiver = " . $_SESSION['user']->userid . " THEN sender END)"))->where("status" . $status)->where("sender=? OR receiver=?", $_SESSION['user']->userid));
 }
Esempio n. 20
0
 /**
  * @throws \Exception
  */
 private function crop()
 {
     $file = new Crop(["x" => $_POST['crop-x'], "y" => $_POST['crop-y'], "x1" => $_POST['crop-x1'], "y1" => $_POST['crop-y1'], "thumbwidth" => 970, "directory" => "../data/uploads/" . Cunity::get("settings")->getSetting("core.filesdir"), "prefix" => "cr_"]);
     $file->filter($_POST['crop-image']);
     $events = new Events();
     if ($events->updateEvent($_POST['eventid'], ["imageId" => $_POST['imageid']])) {
         header("Location: " . Url::convertUrl("index.php?m=events&action=" . $_POST['eventid']));
     }
 }
Esempio n. 21
0
 /**
  * @param \Zend_Config $config
  * @param $destinationFile
  * @param $previewFile
  * @throws \Cunity\Core\Exception
  */
 public function resize(\Zend_Config $config, $destinationFile, $previewFile)
 {
     $resizer = new Resize($config->images);
     $preview = new Resize($config->previewImages);
     $crop = new Crop(["thumbwidth" => "thumbnail", "directory" => "../data/uploads/" . Cunity::get("settings")->getSetting("core.filesdir"), "prefix" => "thumb_"]);
     $resizer->filter($destinationFile);
     $preview->filter($previewFile);
     $crop->filter($destinationFile);
 }
Esempio n. 22
0
 /**
  * @return bool
  * @throws \Exception
  */
 public function validateForm()
 {
     $validateMail = new Email();
     $validateUsername = new Username();
     $validatePassword = new Password();
     if (Cunity::get("settings")->getSetting("register.min_age")) {
         $validateBirthday = new Zend_Validate_Date(["format" => "mm/dd/yyyy"]);
         if (!$validateBirthday->isValid($_POST['birthday'])) {
             $this->errors['birthday'] = implode(',', $validateBirthday->getMessages());
         }
     }
     if (!$validateUsername->isValid($_POST['username'])) {
         $this->errors["username"] = implode(',', $validateUsername->getMessages());
     }
     if (!$validateMail->isValid($_POST['email'])) {
         $this->errors["email"] = implode(',', $validateMail->getMessages());
     }
     if (!$validatePassword->passwordValid($_POST['password'], $_POST['password_repeat'])) {
         $this->errors["password"] = implode(',', $validatePassword->getMessages());
         $this->errors["password_repeat"] = "";
     }
     return empty($this->errors);
 }
Esempio n. 23
0
 /**
  * @throws \Exception
  */
 private function loadData()
 {
     $langIterator = new \DirectoryIterator("modules/Core/languages");
     $designIterator = new \DirectoryIterator("../style");
     foreach ($designIterator as $design) {
         if ($design->isDir() && $design->isReadable() && !$design->isDot()) {
             $this->assignments['availableDesigns'][] = [$design->getBasename(), file_get_contents($design->getRealPath() . DIRECTORY_SEPARATOR . "name.txt")];
         }
     }
     foreach ($langIterator as $lang) {
         if ($lang->isReadable() && $lang->getExtension() == "csv") {
             $this->assignments['availableLanguages'][] = $lang->getBasename('.csv');
         }
     }
     $profileFields = new ProfileFields();
     $this->assignments['profileFields'] = $profileFields->getAll();
     $this->assignments['fieldTypes'] = ProfileFields::$types;
     $this->assignments["config"] = Cunity::get("config");
 }
Esempio n. 24
0
 /** @noinspection PhpUnusedPrivateMethodInspection */
 private function crop()
 {
     $file = new Crop(["x" => $_POST['crop-x'], "y" => $_POST['crop-y'], "x1" => $_POST['crop-x1'], "y1" => $_POST['crop-y1'], "thumbwidth" => $_POST['type'] == "title" ? 970 : 150, "directory" => "../data/uploads/" . Cunity::get("settings")->getSetting("core.filesdir"), "prefix" => "cr_"]);
     $file->filter($_POST['crop-image']);
     if ($_POST['type'] == "title") {
         $_SESSION['user']->titleImage = $_POST['imageid'];
     } else {
         $_SESSION['user']->profileImage = $_POST['imageid'];
     }
     /** @noinspection PhpUndefinedMethodInspection */
     if ($_SESSION['user']->save()) {
         header("Location: " . Url::convertUrl("index.php?m=profile"));
     }
 }
Esempio n. 25
0
 /**
  * @throws \Exception
  */
 public function logout()
 {
     session_destroy();
     setcookie("cunity-login", base64_encode($this->username), time() - 3600, '/', Cunity::get("settings")->getSetting("core.siteurl"));
     setcookie("cunity-login-token", md5($this->salt . "-" . $this->registered . "-" . $this->userhash), time() - 3600, '/', Cunity::get("settings")->getSetting("core.siteurl"));
 }
Esempio n. 26
0
 /**
  * @throws \Cunity\Core\Exception
  */
 public function run()
 {
     $dir = new \DirectoryIterator($this->_directory);
     foreach ($dir as $fileinfo) {
         if (!$fileinfo->isDot() && $fileinfo->isReadable()) {
             if ($fileinfo->getExtension() == "php") {
                 include_once $this->_directory . DIRECTORY_SEPARATOR . $fileinfo->getFilename();
                 $classname = $fileinfo->getBasename(".php");
                 $classnameParts = explode('Version', $classname);
                 if (class_exists($classname) && !$this->versionInstalled($classnameParts[1])) {
                     /** @var DbUpdateVersion $dbCmd */
                     $dbCmd = new $classname(Cunity::get("db"));
                     if ($dbCmd instanceof DbCommandInterface) {
                         /** @noinspection PhpUndefinedMethodInspection */
                         $dbCmd->execute();
                         $dbCmd->updateDatabaseTimestamp($this->versionDb);
                     }
                 }
             }
         }
     }
     $process = new Process();
     $process->recreateSearchIndex();
 }
Esempio n. 27
0
 /**
  *
  */
 public static function initTranslator()
 {
     Cunity::init();
     $locale = new Zend_Locale(Cunity::get('settings')->getSetting('core.language'));
     if (null === self::$zt) {
         self::$zt = new Zend_Translate(['adapter' => 'csv', 'content' => __DIR__ . '/../languages/' . $locale->getLanguage() . '.csv', 'scan' => Zend_Translate::LOCALE_FILENAME, 'locale' => $locale->getLanguage()]);
         /** @noinspection PhpUndefinedMethodInspection */
         self::$zt->addTranslation(array('content' => __DIR__ . '/../languages/' . $locale->getLanguage() . '.csv', 'locale' => $locale->getLanguage()));
         /** @noinspection PhpUndefinedMethodInspection */
         $missingTranslationLog = __DIR__ . '/../../../../resources/log/missing-translations.log';
         if (is_writeable($missingTranslationLog)) {
             self::$zt->setOptions(['log' => new Zend_Log(new Zend_Log_Writer_Stream($missingTranslationLog)), 'logUntranslated' => true]);
         }
         /** @noinspection PhpUndefinedMethodInspection */
         if (!self::$zt->isAvailable($locale->getLanguage())) {
             /** @noinspection PhpUndefinedMethodInspection */
             self::$zt->setLocale(self::$defaultLanguage);
         }
         /** @noinspection PhpUndefinedMethodInspection */
         self::$zt->getLocale();
     }
 }
Esempio n. 28
0
 /**
  * @param $form
  * @throws \Exception
  * @throws \Zend_Config_Exception
  */
 private function save($form)
 {
     $res = [];
     switch ($form) {
         case "settings":
         case "headline":
             foreach ($_POST as $key => $value) {
                 if (strpos($key, "settings-") !== false) {
                     $setting = explode("-", $key);
                     /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
                     $settings = \Cunity\Core\Cunity::get("settings");
                     $res[] = $settings->setSetting(preg_replace('/_/', '.', $setting[1], 1), $value);
                 }
             }
             break;
         case "config":
             $config = new \Zend_Config_Xml("../data/config.xml");
             $configWriter = new \Zend_Config_Writer_Xml(["config" => new \Zend_Config(self::arrayMergeRecursiveDistinct($config->toArray(), $_POST['config'])), "filename" => "../data/config.xml"]);
             $configWriter->write();
             break;
         case "mailtemplates":
             $settings = Cunity::get("settings");
             $res[] = $settings->setSetting("core.mail_header", $_POST['mail_header']);
             $res[] = $settings->setSetting("core.mail_footer", $_POST['mail_footer']);
             break;
         case 'modules':
             Cunity::set('modules', new Modules());
             $modules = Cunity::get("modules");
             $modules->update(['status' => $_POST['status']], 'id = ' . $_POST['id']);
             break;
         case 'update':
             UpdateHelper::update();
             break;
         case 'users':
             Cunity::set('users', new Users());
             /** @var Users $users */
             $users = Cunity::get("users");
             if (null !== $_REQUEST['userid']) {
                 if ('' !== $_REQUEST['groupid']) {
                     $users->update(['groupid' => $_REQUEST['groupid']], 'userid = ' . $_REQUEST['userid']);
                 } else {
                     $users->delete('userid = ' . $_REQUEST['userid']);
                 }
             } else {
                 $users->registerNewUser($_REQUEST);
             }
             break;
     }
     $this->sendResponse($res);
 }