예제 #1
0
파일: views.php 프로젝트: bztsrc/phppe3
 /**
  * Delete layout
  */
 public function delete()
 {
     //! check input
     if (empty($this->id)) {
         throw new \Exception(L('No layout id'));
     }
     if (empty(Core::$user->id) || !Core::$user->has("siteadm")) {
         throw new \Exception(L('No user id'));
     }
     Core::log('A', sprintf("Layout %s deleted by %s", $this->id, Core::$user->name), "cmsaudit");
     DS::exec("DELETE FROM " . static::$_table . " WHERE id=?", [$this->id]);
     DS::exec("DELETE FROM " . Page::$_table . "_list WHERE page_id IN (SELECT id FROM pages WHERE template=?)", [$this->id]);
     DS::exec("DELETE FROM " . Page::$_table . " WHERE template=?", [$this->id]);
 }
예제 #2
0
 public function route($app, $action)
 {
     // keepalive on new sessions and every minute afterwards
     if (empty($_SESSION['pe_lt']) || $_SESSION['pe_lt'] + 60 < Core::$core->now) {
         $_SESSION['pe_lt'] = Core::$core->now;
         $d = @file_get_contents("/proc/loadavg");
         $l = !empty($d) ? explode(" ", $d)[0] : "1.0";
         // queried signal
         try {
             DS::exec("UPDATE " . self::$_table . " SET viewd=CURRENT_TIMESTAMP,load=? WHERE id=?", [$l, $this->id]);
         } catch (\Exception $e) {
             if (Core::$client->ip == "CLI") {
                 echo L("Unable to find cluster table on quorum database.") . "\r\n";
             }
         }
     }
 }
예제 #3
0
파일: EplosCMS.php 프로젝트: bztsrc/phppe3
 function init($cfg)
 {
     //! defaults
     if (empty($cfg["sqldir"])) {
         $cfg["sqldir"] = "data/temp";
     }
     if (empty($cfg["pagesdir"])) {
         $cfg["pagesdir"] = "pages";
     }
     $this->pagesdir = $cfg["pagesdir"];
     //! if it's a special sql refresh request
     if (Core::$core->url == "sqlrefresh" || isset($_REQUEST["sqlrefresh"])) {
         //look data source
         if (!DS::db()) {
             die("ERROR: no db");
         }
         //read the changes
         $sqlFiles = @glob($cfg["sqldir"] . "/sqlchanges-*.sql");
         foreach ($sqlFiles as $sf) {
             //get sql commands from file
             $sqls = str_getcsv(@file_get_contents($sf), ";");
             @unlink($sf);
             //execute one by one
             foreach ($sqls as $query) {
                 DS::exec($query);
             }
         }
         die("OK");
     }
     //! check if there's a CMS generated file for the url
     //! if so, add route for it
     $c = @explode("/", Core::$core->url);
     while (!empty($c)) {
         $f = implode("-SLASH-", $c);
         if (file_exists($cfg["pagesdir"] . "/" . $f . ".php")) {
             self::$page = $cfg["pagesdir"] . "/" . $f . ".php";
             Http::route(Core::$core->url, "\\PHPPE\\EplosCMS");
             break;
         }
         //if not found, put last part in parameters array
         self::$params[] = array_pop($c);
     }
     //reverse the parameters as they were popped in reverse order
     self::$params = @array_reverse(self::$params);
     return true;
 }
예제 #4
0
파일: Email.php 프로젝트: bztsrc/phppe3
 /**
  * Cron job to read mails from queue and send them out
  */
 public function cronMinute($item)
 {
     //! get real mailer backend ($core->mailer points to db queue backend)
     // @codeCoverageIgnoreStart
     if (empty(Core::$core->realmailer)) {
         Core::log('C', L('Real mailer backend not configured!'));
     }
     // @codeCoverageIgnoreEnd
     //! get items from database
     $lastId = 0;
     while ($row = DS::fetch('*', 'email_queue', 'id>?', '', 'id ASC', [$lastId])) {
         $email = new self($row['data']);
         $lastId = $row['id'];
         try {
             if (!$email->send(Core::$core->realmailer)) {
                 // @codeCoverageIgnoreStart
                 throw new \Exception('send() returned false');
             }
             DS::exec('DELETE FROM email_queue WHERE id=?;', [$row['id']]);
         } catch (\Exception $e) {
             Core::log('E', sprintf(L('Unable to send #%s from queue'), $row['id']) . ': ' . $e->getMessage());
         }
         // @codeCoverageIgnoreEnd
         sleep(1);
     }
 }
예제 #5
0
파일: index.php 프로젝트: bztsrc/phppe3
 public function save($f = 0)
 {
     if (empty(static::$_table)) {
         throw new \Exception('no _table');
     }
     $d = DS::db();
     if (empty($d)) {
         throw new \Exception('no ds');
     }
     $a = [];
     foreach (get_object_vars($this) as $k => $v) {
         if ($k[0] != '_' && ($f || $k != 'id') && $k != 'created') {
             $a[$k] = is_scalar($v) ? $v : json_encode($v);
         }
     }
     if (!DS::exec($this->id && !$f ? 'UPDATE ' . static::$_table . ' SET ' . implode('=?,', array_keys($a)) . '=? WHERE id=' . $d->quote($this->id) : 'INSERT INTO ' . static::$_table . ' (' . implode(',', array_keys($a)) . ') VALUES (?' . str_repeat(',?', count($a) - 1) . ')', array_values($a))) {
         return false;
     }
     if (!$this->id || $f) {
         $this->id = $d->lastInsertId();
     }
     return $this->id;
 }
예제 #6
0
파일: pages.php 프로젝트: bztsrc/phppe3
 static function cleanUp($pages = null)
 {
     //! check input
     if (!empty(Core::lib("CMS")->revert)) {
         return;
     }
     if (empty(Core::$user->id) || !Core::$user->has("siteadm|pubadm")) {
         throw new \Exception(L('No user id'));
     }
     if (empty($pages)) {
         $pages = self::getPages();
     }
     //! write audit log
     Core::log('A', sprintf("Purge page history by %s", Core::$user->name), "cmsaudit");
     //! purge old records
     foreach ($pages as $p) {
         if ($p['versions'] > 1) {
             DS::exec("DELETE FROM " . static::$_table . " WHERE id=? AND (lang='' OR lang=?) AND created!=?", [$p['id'], $p['lang'], $p['created']]);
         }
     }
     //! make it published (without history that feature is off)
     DS::exec("UPDATE " . static::$_table . " SET publishid=? WHERE publishid=0", [Core::$user->id]);
 }
예제 #7
0
파일: Gallery.php 프로젝트: bztsrc/phppe3
 /**
  * Function to save image lists
  *
  * @param name
  * @param array of image urls
  */
 static function saveImageList($name, $imgs)
 {
     //! check input
     if (empty($name)) {
         throw new \Exception(L('No imglist name'));
     }
     if (is_string($imgs)) {
         $imgs = str_getcsv($imgs, ",");
     }
     DS::exec("DELETE FROM img_list WHERE list_id=?", [$name]);
     foreach ($imgs as $k => $v) {
         if (!empty($v) && trim($v) != "null") {
             DS::exec("INSERT INTO img_list (list_id,id,ordering) values (?,?,?)", [$name, $v, intval($k)]);
         }
     }
     return true;
 }
예제 #8
0
파일: DB.php 프로젝트: bztsrc/phppe3
 /**
  * Execute a query and return number of affected rows (commands) or data set (select query).
  *
  * @param array             arguments array, values for placeholders
  * @param integer           data source selector
  *
  * @return integer/array    number of affected rows or result set (array of assoc arrays)
  */
 public function execute($arguments = [], $ds = -1)
 {
     //! set data source if requested
     if ($ds != -1) {
         $old_ds = DS::ds();
         DS::ds($ds);
     }
     //! get sql sentance
     $sql = $this->sql();
     if (strpos($sql, '?') !== false && empty($arguments)) {
         throw new DBException(L('Placeholder(s) in SQL without argument') . ': ' . $sql);
     }
     //! execute the query with PHPPE Core
     try {
         $ret = DS::exec($sql, $arguments);
         // @codeCoverageIgnoreStart
     } catch (\Exception $e) {
         throw new DBException(L($e->getMessage()) . ': ' . $sql);
         // @codeCoverageIgnoreEnd
     }
     //! restore data source if changed
     if ($ds != -1) {
         DS::ds($old_ds);
     }
     //! return result
     return $ret;
 }
예제 #9
0
파일: Registry.php 프로젝트: bztsrc/phppe3
 /**
  * Remove a parameter from registry.
  *
  * @param string    key
  */
 public static function del($key)
 {
     //sanitize key
     $key = preg_replace('/[^a-zA-Z0-9_]/', '', $key);
     //remove both database record as well as file
     try {
         @DS::exec('DELETE FROM registry WHERE name=?', [$key]);
     } catch (\Exception $e) {
     }
     @unlink('data/registry/' . $key);
 }
예제 #10
0
 /**
  * Function to save document lists
  *
  * @param name
  * @param array of image urls
  */
 static function saveDocumentList($name, $docs)
 {
     //! check input
     if (empty($name)) {
         throw new \Exception(L('No doclist name'));
     }
     if (is_string($docs)) {
         $docs = str_getcsv($docs, ',');
     }
     DS::exec("DELETE FROM doc_list WHERE list_id=?", [$name]);
     foreach ($docs as $k => $v) {
         if (!empty($v) && trim($v) != "null") {
             DS::exec("INSERT INTO doc_list (list_id,id,ordering) values (?,?,?)", [$name, $v, intval($k)]);
         }
     }
     return true;
 }
예제 #11
0
 function deployworker($arg)
 {
     $id = $arg['id'];
     $rootdir = $arg['rootdir'];
     $dirs = $arg['dirs'];
     $remote = $arg['remote'];
     //! call rsync
     $files = [];
     if (substr($rootdir, -1) != "/") {
         $rootdir .= "/";
     }
     foreach ($dirs as $d) {
         $files[$rootdir . $d] = 1;
     }
     Core::$user->data['remote'] = $remote;
     $files = array_keys($files);
     $path = !empty($remote['path']) ? $remote['path'] : "/var/www/";
     if (!empty($arg['rsync'])) {
         $ret = Tools::ssh("rsync", $files, $path);
     } else {
         $ret = Tools::copy($files, $path);
     }
     //! update status
     DS::exec("UPDATE " . self::$_table . " SET console=?,syncd=CURRENT_TIMESTAMP WHERE id=?", [$id]);
 }
예제 #12
0
파일: Users.php 프로젝트: bztsrc/phppe3
 /**
  * Logout user
  */
 public function logout()
 {
     DS::exec("UPDATE " . static::$_table . " SET logoutd=CURRENT_TIMESTAMP WHERE id=?", [$this->id]);
 }