Example #1
0
 public static function Instance()
 {
     if (self::$instance == null) {
         self::$instance = new Model();
     }
     return self::$instance;
 }
Example #2
0
 public static function get_instance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #3
0
 /**
  * Singleton constructor
  * @return static
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new static();
     }
     return self::$instance;
 }
Example #4
0
 public static function getInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new Model();
     }
     return self::$instance;
 }
Example #5
0
 public function index()
 {
     $model = Model::instance();
     ipAddJs('Ip/Internal/Grid/assets/grid.js');
     ipAddJs('Ip/Internal/Grid/assets/gridInit.js');
     ipAddJs('Ip/Internal/Grid/assets/subgridField.js');
     $notes = array();
     if (isset($_SESSION['Ip']['notes']) && is_array($_SESSION['Ip']['notes'])) {
         $notes = $_SESSION['Ip']['notes'];
     }
     unset($_SESSION['Ip']['notes']);
     $enableUpdate = !defined('MULTISITE_WEBSITES_DIR');
     // Disable update in MultiSite installation.
     $trash = array('size' => \Ip\Internal\Pages\Service::trashSize());
     $data = array('notes' => $notes, 'version' => \Ip\ServiceLocator::storage()->get('Ip', 'version'), 'changedUrl' => $model->getOldUrl() != $model->getNewUrl(), 'oldUrl' => $model->getOldUrl(), 'newUrl' => $model->getNewUrl(), 'migrationsAvailable' => \Ip\Internal\Update\Service::migrationsAvailable(), 'migrationsUrl' => ipActionUrl(array('pa' => 'Update')), 'recoveryPageForm' => \Ip\Internal\System\Helper::recoveryPageForm(), 'emptyPageForm' => \Ip\Internal\System\Helper::emptyPageForm(), 'trash' => $trash);
     $content = ipView('view/index.php', $data)->render();
     if ($enableUpdate) {
         ipAddJs('Ip/Internal/System/assets/update.js');
     }
     if ($trash['size'] > 0) {
         ipAddJs('Ip/Internal/Core/assets/js/angular.js');
         ipAddJs('Ip/Internal/System/assets/trash.js');
     }
     ipAddJs('Ip/Internal/System/assets/migrations.js');
     ipAddJs('assets/cache.js');
     return $content;
 }
Example #6
0
 private static function checkForUpdates()
 {
     $module = Model::instance();
     $systemInfo = $module->getIpNotifications();
     if ($systemInfo != '') {
         //send an email
         $md5 = \Ip\ServiceLocator::storage()->get('Ip', 'lastSystemMessageSent');
         if (!$md5 || $md5 != md5(serialize($systemInfo))) {
             //we have a new message
             $message = '';
             $messages = $systemInfo;
             if (is_array($messages)) {
                 foreach ($messages as $messageVal) {
                     $message .= '<p>' . $messageVal->message . '</p>';
                 }
                 $onlyStatusMessages = true;
                 foreach ($messages as $messageVal) {
                     if ($messageVal->type != 'status') {
                         $onlyStatusMessages = false;
                     }
                 }
                 if ($onlyStatusMessages) {
                     return;
                     //TODO replace to something that would not terminate execution of following scripts if they will be there some day
                 }
             } else {
                 return;
                 //TODO replace to something that would not terminate execution of following scripts if they will be there some day
             }
             ipEvent('ipSystemMessages', array('messages' => $messages));
             \Ip\ServiceLocator::storage()->set('Ip', 'lastSystemMessageSent', md5(serialize($systemInfo)));
         }
     }
 }
Example #7
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new Model();
     }
     return self::$instance;
 }
Example #8
0
 public function downloadTheme($name, $url, $signature)
 {
     $model = Model::instance();
     //download theme
     $net = new \Ip\Internal\NetHelper();
     $themeTempFilename = $net->downloadFile($url, ipFile('file/secure/tmp/'), $name . '.zip');
     if (!$themeTempFilename) {
         throw new \Ip\Exception('Theme file download failed.');
     }
     $archivePath = ipFile('file/secure/tmp/' . $themeTempFilename);
     //check signature
     $fileMd5 = md5_file($archivePath);
     $rsa = new \Crypt_RSA();
     $rsa->loadKey($this->publicKey);
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $verified = $rsa->verify($fileMd5, base64_decode($signature));
     if (!$verified) {
         throw new \Ip\Exception('Theme signature verification failed.');
     }
     //extract
     $helper = Helper::instance();
     $secureTmpDir = ipFile('file/secure/tmp/');
     $tmpExtractedDir = \Ip\Internal\File\Functions::genUnoccupiedName($name, $secureTmpDir);
     \Ip\Internal\Helper\Zip::extract($secureTmpDir . $themeTempFilename, $secureTmpDir . $tmpExtractedDir);
     unlink($archivePath);
     //install
     $extractedDir = $helper->getFirstDir($secureTmpDir . $tmpExtractedDir);
     $installDir = $model->getThemeInstallDir();
     $newThemeDir = \Ip\Internal\File\Functions::genUnoccupiedName($name, $installDir);
     rename($secureTmpDir . $tmpExtractedDir . '/' . $extractedDir, $installDir . $newThemeDir);
 }
Example #9
0
 protected static function getAdminNavbarHtml()
 {
     $requestData = \Ip\ServiceLocator::request()->getRequest();
     $curModTitle = '';
     $curModUrl = '';
     $curModIcon = '';
     if (!empty($requestData['aa'])) {
         $parts = explode('.', $requestData['aa']);
         $curModule = $parts[0];
     } else {
         $curModule = "Content";
     }
     if (isset($curModule) && $curModule) {
         $title = $curModule;
         $plugin = \Ip\Internal\Plugins\Service::getPluginConfig($curModule);
         if ($plugin) {
             $title = $plugin['title'];
         }
         $curModTitle = __($title, 'Ip-admin', false);
         $curModUrl = ipActionUrl(array('aa' => $curModule . '.index'));
         $curModIcon = Model::getAdminMenuItemIcon($curModule);
     }
     $navbarButtons = array(array('text' => '', 'hint' => __('Logout', 'Ip-admin', false), 'url' => ipActionUrl(array('sa' => 'Admin.logout')), 'class' => 'ipsAdminLogout', 'faIcon' => 'fa-power-off'));
     $navbarButtons = ipFilter('ipAdminNavbarButtons', $navbarButtons);
     $navbarCenterElements = ipFilter('ipAdminNavbarCenterElements', array());
     $data = array('menuItems' => Model::instance()->getAdminMenuItems($curModule), 'curModTitle' => $curModTitle, 'curModUrl' => $curModUrl, 'curModIcon' => $curModIcon, 'navbarButtons' => array_reverse($navbarButtons), 'navbarCenterElements' => $navbarCenterElements);
     $html = ipView('view/navbar.php', $data)->render();
     return $html;
 }
Example #10
0
 protected static function initConfig()
 {
     ipAddCss('Ip/Internal/Core/assets/admin/admin.css');
     ipAddJs('Ip/Internal/Core/assets/js/jquery-ui/jquery-ui.js');
     ipAddJsVariable('ipTranslationSaving', __('Saving...', 'Ip-admin', false));
     ipAddJs('Ip/Internal/Design/assets/optionsBox.js');
     ipAddJsVariable('ipModuleDesignConfiguration', Helper::getConfigurationBoxHtml());
     if (file_exists(ipThemeFile(Model::INSTALL_DIR . 'Options.js'))) {
         ipAddJs(ipThemeUrl(Model::INSTALL_DIR . 'Options.js'));
     } elseif (file_exists(ipThemeFile(Model::INSTALL_DIR . 'options.js'))) {
         ipAddJs(ipThemeUrl(Model::INSTALL_DIR . 'options.js'));
     }
     $model = Model::instance();
     $theme = $model->getTheme(ipConfig()->theme());
     if (!$theme) {
         throw new \Ip\Exception("Theme doesn't exist");
     }
     $options = $theme->getOptionsAsArray();
     $fieldNames = array();
     foreach ($options as $option) {
         if (empty($option['name'])) {
             continue;
         }
         $fieldNames[] = $option['name'];
     }
     ipAddJsVariable('ipModuleDesignOptionNames', $fieldNames);
 }
Example #11
0
 /**
  * @param string $themeName
  * @param string $lessFile
  * @return string
  */
 public function compileFile($themeName, $lessFile)
 {
     $model = Model::instance();
     $theme = $model->getTheme($themeName);
     $options = $theme->getOptionsAsArray();
     $configModel = ConfigModel::instance();
     $config = $configModel->getAllConfigValues($themeName);
     $less = "@import '{$lessFile}';";
     $less .= $this->generateLessVariables($options, $config);
     $css = '';
     try {
         require_once ipFile('Ip/Lib/less.php/Less.php');
         $themeDir = ipFile('Theme/' . $themeName . '/assets/');
         $ipContentDir = ipFile('Ip/Internal/Core/assets/ipContent/');
         // creating new context to pass theme assets directory dynamically to a static callback function
         $context = $this;
         $callback = function ($parseFile) use($context, $themeDir) {
             return $context->overrideImportDirectory($themeDir, $parseFile);
         };
         $parserOptions = array('import_callback' => $callback, 'cache_dir' => ipFile('file/tmp/less/'), 'relativeUrls' => false, 'sourceMap' => true);
         $parser = new \Less_Parser($parserOptions);
         $directories = array($themeDir => '', $ipContentDir => '');
         $parser->SetImportDirs($directories);
         $parser->parse($less);
         $css = $parser->getCss();
         $css = "/* Edit {$lessFile}, not this file. */" . "\n" . $css;
     } catch (\Exception $e) {
         ipLog()->error('Less compilation error: Theme - ' . $e->getMessage());
     }
     return $css;
 }
Example #12
0
 static function get_instance()
 {
     if (self::$instance instanceof self) {
         return self::$instance;
     }
     return self::$instance = new self();
 }
Example #13
0
 public static function __callStatic($function, $arguments)
 {
     // avoid cap errors
     if (strtolower($function) == strtolower(get_called_class())) {
         // call the constructor from an instance
         if (is_null(self::$instance)) {
             self::$instance = new self();
         }
         return self::$instance;
     }
 }
Example #14
0
 public static function urlHasChanged()
 {
     $model = Model::instance();
     $oldUrl = $model->getOldUrl();
     $newUrl = $model->getNewUrl();
     if ($oldUrl != $newUrl) {
         return true;
     } else {
         return false;
     }
 }
Example #15
0
 public function getTheme($name = null, $dir = null, $url = null)
 {
     if ($name == null) {
         $name = ipConfig()->theme();
     }
     if ($dir == null) {
         $dir = ipFile('Theme/');
     }
     $model = Model::instance();
     $theme = $model->getTheme($name, $dir, $url);
     return $theme;
 }
Example #16
0
 /**
  * Devuelve la instancia
  * Model::getInstance()
  */
 public static function getInstance()
 {
     if (null === self::$instance) {
         // Creamos una nueva conexión
         try {
             self::$instance = new PDO("mysql:host=mysql.christianmiguez.com;dbname=" . self::DB_NAME . "; charset=utf8", self::DB_USER, self::DB_PASS);
             self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         } catch (PDOException $e) {
             $this->_error = $e->getMessage();
         }
     }
     return self::$instance;
 }
Example #17
0
 public static function query($columns = ['*'])
 {
     if (!isset(self::$instance)) {
         self::$instance = new self([]);
     }
     self::$table = 'eli_' . strtolower(get_called_class());
     $get = 'select ';
     foreach ($columns as $key => $val) {
         $get .= $val;
         if ($key != end_key($columns)) {
             $get .= ', ';
         } else {
             $get .= ' ';
         }
     }
     self::$query = $get . ' from ' . self::$table;
     return self::$instance;
 }
Example #18
0
 public function __construct()
 {
     if (is_object(self::$instance)) {
         $this->dbh = self::$instance->dbh;
         return null;
     }
     $config = Init::config('database');
     $dsn = $config['driver'] . ':host=' . $config['hostname'] . ';dbname=' . $config['database'] . ';charset=' . $config['charset'];
     try {
         $this->dbh = new PDO($dsn, $config['username'], $config['password']);
         $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
         $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
         //$this->dbh->query('SET NAMES utf8');
     } catch (PDOException $exc) {
         echo $exc->getMessage();
     }
     self::$instance = $this;
 }
Example #19
0
<?php

$model = Model::instance($_REQUEST['_m']);
$criteria = array();
foreach ($model->fields() as $f) {
    if (is_a($f, 'ChoiceField') || is_a($f, 'MultipleChoiceField')) {
        $criteria[] = $f->to_search_field();
    }
}
$search = new Form($criteria, $_REQUEST);
$data = array();
$data['_v'] = 'list';
$data['_m'] = $_REQUEST['_m'];
if ($search->is_valid()) {
    $data = array_merge($data, $search->cleaned_data());
}
$_REQUEST['_r'] = config('greenroom_admin') . '?' . http_build_query($data);
$documents = $backend->find($_REQUEST['_m'])->sort(array('publish_date' => -1));
if ($search->is_valid()) {
    $documents = $model->find($search->cleaned_data());
}
$new_link = $model->new_link($search->cleaned_data());
echo "<h3>List " . ucwords($_REQUEST['_m']) . "</h3>";
echo sprintf('<a href="%s">New</a>', $new_link);
if (!empty($criteria)) {
    echo $search->open();
    echo $search->as_div();
    ?>
<div><input type="submit" name="submit" value="Search"></div><?php 
    echo $search->close();
}
Example #20
0
 public function testContainer()
 {
     $person = \Model::instance()->m('PersonModelTest');
     $this->assertTrue($person instanceof PersonModelTest);
 }
Example #21
0
 public static function setAdminLogin($username)
 {
     $model = Model::instance();
     $model->setAdminLogin($username);
 }
 public function logout()
 {
     Model::instance()->logout();
     if (ipRequest()->isAjax()) {
         return new \Ip\Response\Json(array());
     } else {
         return new \Ip\Response\Redirect(ipHomeUrl());
     }
 }
 /**
  * 单例
  * @param string $className
  * @return CronModel
  */
 public static function instance($className = __CLASS__)
 {
     return parent::instance($className);
 }
Example #24
0
 private function removeFile($file, $secure, $forced = false)
 {
     if (basename($file) == '.htaccess') {
         //for security reasons we don't allow to remove .htaccess files
         return false;
     }
     $baseDir = 'file/repository/';
     if ($secure) {
         $baseDir = 'file/secure/';
     }
     $realFile = realpath(ipFile($baseDir . $file));
     if (strpos($realFile, realpath(ipFile($baseDir))) !== 0) {
         return false;
     }
     $model = Model::instance();
     $usages = $model->whoUsesFile($file);
     if (!$forced && !empty($usages)) {
         return false;
     }
     if (!$secure) {
         $reflectionModel = ReflectionModel::instance();
         $reflectionModel->removeReflections($file);
     }
     if (file_exists($realFile) && is_file($realFile) && is_writable($realFile)) {
         unlink($realFile);
     }
     return true;
 }
 public static function getInstance()
 {
     if (Model::$instance == null) {
         Model::$instance = new Model();
     }
     return Model::$instance;
 }
Example #26
0
 public function logout()
 {
     Model::instance()->logout();
     return new \Ip\Response\Redirect(ipFileUrl('admin/'));
 }