Example #1
0
 public static function delete($id)
 {
     ipEvent('ipBeforeLanguageDeleted', array('id' => $id));
     ipDb()->delete('language', array('id' => $id));
     ipContent()->_invalidateLanguages();
     ipEvent('ipLanguageDeleted', array('id' => $id));
 }
Example #2
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 #3
0
 public static function duplicateRevision($oldRevisionId, $pageId = null, $published = null)
 {
     $oldRevision = self::getRevision($oldRevisionId);
     if (!$oldRevision) {
         throw new \Ip\Exception\Revision("Can't find old revision: " . esc($oldRevisionId));
     }
     if ($pageId !== null) {
         $oldRevision['pageId'] = $pageId;
     }
     $newRevisionId = self::createRevision($oldRevision['pageId'], 0);
     if ($published !== null) {
         self::publishRevision($newRevisionId);
     }
     $eventData = array('newRevisionId' => $newRevisionId, 'basedOn' => $oldRevisionId);
     ipEvent('ipPageRevisionDuplicated', $eventData);
     return $newRevisionId;
 }
Example #4
0
 public function index()
 {
     $this->init();
     if (ipRequest()->getRequest('pass', '') != ipGetOption('Config.cronPassword')) {
         ipLog()->notice('Cron.incorrectPassword: Incorrect cron password from ip `{ip}`.', array('ip' => ipRequest()->getServer('REMOTE_ADDR')));
         $response = new \Ip\Response();
         $response->setContent('Fail. Please see logs for details.');
         return $response;
     }
     ipStorage()->set('Cron', 'lastExecutionStart', time());
     $data = array('firstTimeThisYear' => $this->firstTimeThisYear, 'firstTimeThisMonth' => $this->firstTimeThisMonth, 'firstTimeThisWeek' => $this->firstTimeThisWeek, 'firstTimeThisDay' => $this->firstTimeThisDay, 'firstTimeThisHour' => $this->firstTimeThisHour, 'lastTime' => $this->lastTime, 'test' => ipRequest()->getQuery('test'));
     ipLog()->info('Cron.started', $data);
     ipEvent('ipCronExecute', $data);
     ipStorage()->set('Cron', 'lastExecutionEnd', time());
     ipLog()->info('Cron.finished');
     $response = new \Ip\Response();
     $response->setContent(__('OK', 'Ip-admin'));
     return $response;
 }
Example #5
0
 /**
  * @ignore
  */
 public function close()
 {
     ipEvent('ipBeforeApplicationClosed');
     ipDb()->disconnect();
 }
Example #6
0
 public static function removePlugin($pluginName)
 {
     $activePlugins = self::getActivePluginNames();
     if (in_array($pluginName, $activePlugins)) {
         throw new \Ip\Exception\Plugin\Setup('Please deactivate the plugin before removing it.');
     }
     $pluginRecord = self::getPluginRecord($pluginName);
     if ($pluginRecord) {
         $version = $pluginRecord['version'];
     } else {
         $version = null;
     }
     self::executeSqlIfExists(ipFile('Plugin/' . esc($pluginName) . '/Setup/remove.sql'));
     $workerClass = 'Plugin\\' . $pluginName . '\\Setup\\Worker';
     if (method_exists($workerClass, 'remove')) {
         $worker = new $workerClass($version);
         $worker->remove();
     }
     $dbh = ipDb()->getConnection();
     $sql = '
     DELETE FROM
         ' . ipTable('plugin') . '
     WHERE
         `name` = :pluginName
     ';
     $params = array('pluginName' => $pluginName);
     $q = $dbh->prepare($sql);
     $q->execute($params);
     $pluginDir = ipFile('Plugin/' . $pluginName);
     try {
         $result = Helper::removeDir($pluginDir);
         if (!$result) {
             throw new \Ip\Exception\Plugin\Setup('Can\'t remove folder ' . esc($pluginDir));
         }
     } catch (\Ip\PhpException $e) {
         throw new \Ip\Exception\Plugin\Setup('Can\'t remove folder ' . esc($pluginDir));
     }
     ipLog()->info('Ip.pluginRemoved: {plugin} {version} removed.', array('plugin' => $pluginName, 'version' => $version));
     ipEvent('ipPluginRemoved', array('name' => $pluginName, 'version' => $version));
 }
Example #7
0
 /**
  * Completely remove widget.
  *
  * @param int $widgetId
  */
 public static function removeWidget($widgetId)
 {
     $widgetRecord = self::getWidgetRecord($widgetId);
     $widgetObject = self::getWidgetObject($widgetRecord['name']);
     ipEvent('ipBeforeWidgetRemoved', $widgetRecord);
     if ($widgetObject) {
         $widgetObject->delete($widgetId, $widgetRecord['data']);
     }
     ipDb()->delete('widget', array('id' => $widgetId));
     ipEvent('ipAfterWidgetRemoved', $widgetRecord);
 }
Example #8
0
 /**
  * Set user as logged in
  * @param int $id User id
  * @return void
  */
 function login($id)
 {
     ipEvent('ipUserLogin', array('userId' => $id));
     $_SESSION['ipUserId'] = $id;
 }
Example #9
0
 /**
  * @param string $source
  * @param string $destination
  * @param array $options
  * @return string
  */
 public function createReflection($source, $destination, $options)
 {
     $absoluteSource = str_replace('\\', '/', realpath(ipFile('file/repository/' . $source)));
     $absoluteDestinationDir = dirname(ipFile('file/' . $destination));
     $destinationFileName = basename($destination);
     if (!is_dir($absoluteDestinationDir)) {
         mkdir($absoluteDestinationDir, 0777, $recursive = true);
     }
     if (!is_file($absoluteSource)) {
         return false;
     }
     $data = array('source' => $absoluteSource, 'destination' => $absoluteDestinationDir . '/' . $destinationFileName, 'options' => $options);
     ipJob('ipCreateReflection', $data);
     ipEvent('ipReflectionCreated', $data);
     if (is_file($absoluteDestinationDir . '/' . $destinationFileName)) {
         return true;
     } else {
         return false;
     }
 }
Example #10
0
 public function createMenu()
 {
     $request = ipRequest();
     $request->mustBePost();
     $languageCode = $request->getPost('languageCode');
     $title = $request->getPost('title');
     $type = $request->getPost('type');
     if (empty($title)) {
         $title = __('Untitled', 'Ip-admin', false);
     }
     $pageId = Service::createMenu($languageCode, null, $title, $type);
     $menu = ipContent()->getPage($pageId);
     $eventData = $request->getPost();
     $eventData['id'] = $pageId;
     ipEvent('ipFormCreateMenuSubmitted', $eventData);
     $answer = array('status' => 'success', 'menuName' => $menu->getAlias());
     return new \Ip\Response\Json($answer);
 }
Example #11
0
 public function setAdminLogin($username)
 {
     $administrator = \Ip\Internal\Administrators\Service::getByUsername($username);
     $ip = ipRequest()->getServer('REMOTE_ADDR');
     Backend::login($administrator['id']);
     ipEvent('ipAdminLoginSuccessful', array('username' => $username, 'id' => $administrator['id']));
     ipLog()->info('Admin.loggedIn: {username} from {ip}', array('username' => $username, 'ip' => $ip));
 }
Example #12
0
 /**
  * We assume page is safe to delete.
  *
  * @param int $pageId
  * @return int Count of deleted pages.
  */
 protected static function _removeDeletedPage($pageId)
 {
     $deletedPageCount = 0;
     $children = ipDb()->selectAll('page', array('id', 'isDeleted'), array('parentId' => $pageId));
     foreach ($children as $child) {
         if ($child['isDeleted']) {
             $deletedPageCount += static::_removeDeletedPage($child['id']);
         } else {
             // This should never happen!
             ipLog()->error('Page.pageHasDeletedParent: page {pageId}, parent set to null', array('pageId' => $child['id']));
             ipDb()->update('page', array('parentId' => null), array('id' => $child['id']));
         }
     }
     ipEvent('ipBeforePageRemoved', array('pageId' => $pageId));
     $count = ipDb()->delete('page', array('id' => $pageId));
     ipPageStorage($pageId)->removeAll();
     ipEvent('ipPageRemoved', array('pageId' => $pageId));
     $deletedPageCount += (int) $count;
     return $deletedPageCount;
 }
Example #13
0
 public function afterUpdate($id, $newData)
 {
     $updated = Db::getLanguageById($id);
     if ($updated['url'] != $this->beforeUpdate['url']) {
         $languagePath = $updated['url'] == '' ? '' : $updated['url'] . '/';
         $languagePathBefore = $this->beforeUpdate['url'] == '' ? '' : $this->beforeUpdate['url'] . '/';
         $oldUrl = ipConfig()->baseUrl() . $languagePathBefore;
         $newUrl = ipConfig()->baseUrl() . $languagePath;
         ipEvent('ipUrlChanged', array('oldUrl' => $oldUrl, 'newUrl' => $newUrl));
         $oldUrl = ipConfig()->baseUrl() . 'index.php/' . $languagePathBefore;
         $newUrl = ipConfig()->baseUrl() . 'index.php/' . $languagePath;
         ipEvent('ipUrlChanged', array('oldUrl' => $oldUrl, 'newUrl' => $newUrl));
     }
     if ($updated['code'] != $this->beforeUpdate['code']) {
         ipDb()->update('page', array('languageCode' => $updated['code']), array('languageCode' => $this->beforeUpdate['code']));
     }
     ipContent()->_invalidateLanguages();
     ipEvent('ipLanguageUpdated', array('old' => $this->beforeUpdate, 'new' => $updated));
 }
Example #14
0
 public function installTheme($themeName)
 {
     $themes = $this->getAvailableThemes();
     if (!isset($themes[$themeName])) {
         throw new \Ip\Exception("Theme '" . esc($themeName) . "' does not exist.");
     }
     $theme = $themes[$themeName];
     ipEvent('ipBeforeThemeInstalled', array('themeName' => $themeName));
     \Ip\ServiceLocator::storage()->set('Ip', 'theme', $themeName);
     $service = Service::instance();
     $service->saveWidgetOptions($theme);
     //write down default theme options
     $options = $theme->getOptionsAsArray();
     foreach ($options as $option) {
         if (empty($option['name']) || empty($option['default'])) {
             continue;
         }
         $configModel = ConfigModel::instance();
         $newValue = $configModel->getConfigValue($themeName, $option['name'], $option['default']);
         $configModel->setConfigValue($themeName, $option['name'], $newValue);
     }
     ipEvent('ipThemeInstalled', array('themeName' => $themeName));
 }
Example #15
0
 public static function clearCache()
 {
     ipStorage()->set('Ip', 'cacheVersion', ipStorage()->get('Ip', 'cacheVersion', 1) + 1);
     ipEvent('ipCacheClear');
 }