PHP Method modX::lexicon Code Examples

PHP modX::lexicon - 30 examples found. These are the top rated real world PHP examples of method modX::lexicon extracted from open source projects. You can rate examples to help us improve the quality of examples
 /**
  * Handle DELETE requests
  * @return array
  */
 public function delete()
 {
     $id = $this->getProperty($this->primaryKeyField, false);
     if (empty($id)) {
         return $this->failure($this->modx->lexicon('rest.err_field_ns', array('field' => $this->primaryKeyField)));
     }
     $c = $this->getPrimaryKeyCriteria($id);
     $this->object = $this->modx->getObject($this->classKey, $c);
     if (empty($this->object)) {
         return $this->failure($this->modx->lexicon('rest.err_obj_nf', array('class_key' => $this->classKey)));
     }
     if (!empty($this->deleteRequiredFields)) {
         if (!$this->checkRequiredFields($this->deleteRequiredFields)) {
             return $this->failure();
         }
     }
     $this->object->fromArray($this->getProperties());
     $beforeDelete = $this->beforeDelete();
     if ($beforeDelete !== true) {
         return $this->failure($beforeDelete === false ? $this->errorMessage : $beforeDelete);
     }
     if (!$this->object->{$this->deleteMethod}()) {
         $this->setObjectErrors();
         return $this->failure($this->modx->lexicon('rest.err_class_remove', array('class_key' => $this->classKey)));
     }
     $objectArray = $this->object->toArray();
     $this->afterDelete($objectArray);
     return $this->success('', $objectArray);
 }
 public function getUserTop()
 {
     /* topbar profile links. Moved from class Discuss */
     if ($this->discuss->user->isLoggedIn) {
         $authphs = array('authLink' => '<a href="' . $this->discuss->request->makeUrl('logout') . '">Logout</a>');
         $authphs = array_merge($this->discuss->user->toArray('user.'), $authphs);
         $authphs['user.avatar_url'] = $this->discuss->user->getAvatarUrl();
         /* Get counts */
         $authphs['user.unread_messages_count'] = $newMessages = $this->discuss->user->countUnreadMessages();
         $authphs['user.unread_posts_count'] = $unreadPosts = $this->discuss->user->countUnreadPosts();
         $authphs['user.new_replies_count'] = $newReplies = $this->discuss->user->countNewReplies();
         $authphs['user.unanswered_questions_count'] = $unansweredQuestions = $this->discuss->user->countUnansweredQuestions();
         $authphs['user.no_replies_count'] = $noReplies = $this->discuss->user->countWithoutReplies();
         /* Format counts nicely */
         $authphs['user.unread_messages'] = $newMessages > 1 ? $this->modx->lexicon('discuss.user.new_messages', array('total' => $newMessages)) : ($newMessages == 1 ? $this->modx->lexicon('discuss.user.one_new_message') : $this->modx->lexicon('discuss.user.no_new_messages'));
         $authphs['user.unread_posts'] = $unreadPosts > 1 ? $this->modx->lexicon('discuss.user.new_posts', array('total' => $unreadPosts)) : ($unreadPosts == 1 ? $this->modx->lexicon('discuss.user.one_new_post') : $this->modx->lexicon('discuss.user.no_new_posts'));
         $authphs['user.new_replies'] = $newReplies > 1 ? $this->modx->lexicon('discuss.user.new_replies', array('total' => $newReplies)) : ($newReplies == 1 ? $this->modx->lexicon('discuss.user.one_new_reply') : $this->modx->lexicon('discuss.user.no_new_replies'));
         $authphs['user.unanswered_questions'] = $unansweredQuestions > 1 ? $this->modx->lexicon('discuss.user.unanswered_questions', array('total' => $unansweredQuestions)) : ($unansweredQuestions == 1 ? $this->modx->lexicon('discuss.user.one_unanswered_question') : $this->modx->lexicon('discuss.user.no_unanswered_questions'));
         $authphs['user.no_replies'] = $noReplies > 1 ? $this->modx->lexicon('discuss.user.no_replies', array('total' => $noReplies)) : ($noReplies == 1 ? $this->modx->lexicon('discuss.user.one_no_reply') : $this->modx->lexicon('discuss.user.no_no_replies'));
         $this->discuss->user->isGlobalModerator();
         $this->discuss->user->isAdmin();
     } else {
         $authphs = array('authLink' => '<a href="' . $this->discuss->request->makeUrl('login') . '">Login</a>', 'user.avatar_url' => '', 'user.unread_messages' => '');
     }
     $this->modx->toPlaceholders($authphs, 'discuss');
 }
Example #3
0
 /**
  * Checks to see if field value is an actual email address.
  */
 public function email($key, $value)
 {
     /* validate length and @ */
     $pattern = "^[^@]{1,64}\\@[^\\@]{1,255}\$";
     $condition = $this->config['use_multibyte'] ? @mb_ereg($pattern, $value) : @ereg($pattern, $value);
     if (!$condition) {
         return $this->modx->lexicon('rsvpme.email_invalid');
     }
     $email_array = explode("@", $value);
     $local_array = explode(".", $email_array[0]);
     for ($i = 0; $i < sizeof($local_array); $i++) {
         $pattern = "^(([A-Za-z0-9!#\$%&'*+/=?^_`{|}~-][A-Za-z0-9!#\$%&'*+/=?^_`{|}~\\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))\$";
         $condition = $this->config['use_multibyte'] ? @mb_ereg($pattern, $local_array[$i]) : @ereg($pattern, $local_array[$i]);
         if (!$condition) {
             return $this->modx->lexicon('rsvpme.email_invalid');
         }
     }
     /* validate domain */
     $pattern = "^\\[?[0-9\\.]+\\]?\$";
     $condition = $this->config['use_multibyte'] ? @mb_ereg($pattern, $email_array[1]) : @ereg($pattern, $email_array[1]);
     if (!$condition) {
         $domain_array = explode(".", $email_array[1]);
         if (sizeof($domain_array) < 2) {
             return $this->modx->lexicon('rsvpme.email_invalid_domain');
         }
         for ($i = 0; $i < sizeof($domain_array); $i++) {
             $pattern = "^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))\$";
             $condition = $this->config['use_multibyte'] ? @mb_ereg($pattern, $domain_array[$i]) : @ereg($pattern, $domain_array[$i]);
             if (!$condition) {
                 return $this->modx->lexicon('rsvpme.email_invalid_domain');
             }
         }
     }
     return true;
 }
Example #4
0
 /**
  * Gets the viewing message for the bottom of the thread
  *
  * @access public
  * @param string $placePrefix
  * @return string The who is viewing message
  */
 public function getViewing($placePrefix = 'thread')
 {
     if (!$this->xpdo->getOption('discuss.show_whos_online', null, true)) {
         return '';
     }
     if (!$this->xpdo->hasPermission('discuss.view_online')) {
         return '';
     }
     $canViewProfiles = $this->xpdo->hasPermission('discuss.view_profiles');
     $c = $this->xpdo->newQuery('disSession');
     $c->innerJoin('disUser', 'User');
     $c->select($this->xpdo->getSelectColumns('disSession', 'disSession', '', array('id')));
     $c->select(array('CONCAT_WS(":",User.id,IF(User.use_display_name,User.display_name,User.username)) AS reader'));
     $c->where(array('disSession.place' => $placePrefix . ':' . $this->get('id')));
     $c->groupby('disSession.user');
     $sessions = $this->xpdo->getCollection('disSession', $c);
     if (!empty($sessions)) {
         $members = array();
         foreach ($sessions as $member) {
             $r = explode(':', $member->get('reader'));
             $members[] = $canViewProfiles ? '<a href="' . $this->xpdo->discuss->request->makeUrl('user', array('type' => 'username', 'user' => str_replace('%20', '', $r[0]))) . '">' . $r[1] . '</a>' : $r[1];
         }
         $members = array_unique($members);
         $members = implode(',', $members);
     } else {
         $members = $this->xpdo->lexicon('discuss.zero_members');
     }
     $c = $this->xpdo->newQuery('disSession');
     $c->where(array('place' => $placePrefix . ':' . $this->get('id'), 'user' => 0));
     $guests = $this->xpdo->getCount('disSession', $c);
     return $this->xpdo->lexicon('discuss.thread_viewing', array('members' => $members, 'guests' => $guests));
 }
Example #5
0
 /**
  * Formats date to "10 minutes ago" or "Yesterday in 22:10"
  * This algorithm taken from https://github.com/livestreet/livestreet/blob/7a6039b21c326acf03c956772325e1398801c5fe/engine/modules/viewer/plugs/function.date_format.php
  *
  * @param string $date Timestamp to format
  * @param string $dateFormat
  *
  * @return string
  */
 public function dateFormat($date, $dateFormat = null)
 {
     //print_r($date);die;
     $date = preg_match('/^\\d+$/', $date) ? $date : strtotime($date);
     $dateFormat = !empty($dateFormat) ? $dateFormat : $this->MlmSystem->getOption('format_date');
     $current = time();
     $delta = $current - $date;
     if ($this->MlmSystem->getOption('format_date_now')) {
         if ($delta < $this->MlmSystem->getOption('format_date_now')) {
             return $this->modx->lexicon('mlmsystem_date_now');
         }
     }
     if ($this->MlmSystem->getOption('format_date_minutes')) {
         $minutes = round($delta / 60);
         if ($minutes < $this->MlmSystem->getOption('format_date_minutes')) {
             if ($minutes > 0) {
                 return $this->declension($minutes, $this->modx->lexicon('mlmsystem_date_minutes_back', array('minutes' => $minutes)));
             } else {
                 return $this->modx->lexicon('mlmsystem_date_minutes_back_less');
             }
         }
     }
     if ($this->MlmSystem->getOption('format_date_hours')) {
         //
         $hours = round($delta / 3600);
         if ($hours < $this->MlmSystem->getOption('format_date_hours')) {
             if ($hours > 0) {
                 return $this->declension($hours, $this->modx->lexicon('mlmsystem_date_hours_back', array('hours' => $hours)));
             } else {
                 return $this->modx->lexicon('mlmsystem_date_hours_back_less');
             }
         }
     }
     if ($this->MlmSystem->getOption('format_date_day')) {
         switch (date('Y-m-d', $date)) {
             case date('Y-m-d'):
                 $day = $this->modx->lexicon('mlmsystem_date_today');
                 break;
             case date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'))):
                 $day = $this->modx->lexicon('mlmsystem_date_yesterday');
                 break;
             case date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'))):
                 $day = $this->modx->lexicon('mlmsystem_date_tomorrow');
                 break;
             default:
                 $day = null;
         }
         if ($day) {
             $format = str_replace("day", preg_replace("#(\\w{1})#", '\\\\${1}', $day), $this->MlmSystem->getOption('format_date_day'));
             return date($format, $date);
         }
     }
     $m = date("n", $date);
     $month_arr = $this->modx->fromJSON($this->modx->lexicon('mlmsystem_date_months'));
     $month = $month_arr[$m - 1];
     $format = preg_replace("~(?<!\\\\)F~U", preg_replace('~(\\w{1})~u', '\\\\${1}', $month), $dateFormat);
     return date($format, $date);
 }
 public function mailhideUrl($email)
 {
     if (empty($this->config[FormItReCaptcha::OPT_PUBLIC_KEY]) || empty($this->config[FormItReCaptcha::OPT_PRIVATE_KEY])) {
         return $this->error($this->modx->lexicon('recaptcha.mailhide_no_api_key'));
     }
     $ky = pack('H*', $this->config[FormItReCaptcha::OPT_PRIVATE_KEY]);
     $cryptmail = $this->aesEncrypt($email, $ky);
     return 'http://mailhide.recaptcha.net/d?k=' . $this->config[FormItReCaptcha::OPT_PUBLIC_KEY] . '&c=' . $this->mailhideUrlbase64($cryptmail);
 }
Example #7
0
 /**
  * Checks to see if the field is a valid date. Allows for date formatting as
  * well.
  */
 public function isDate($key, $value, $format = '')
 {
     $ts = strtotime($value);
     if ($ts === false) {
         return $this->modx->lexicon('register.not_date');
     }
     if (!empty($format)) {
         $this->fields[$key] = strftime($format, $ts);
     }
     return true;
 }
Example #8
0
 /**
  * Load the reCaptcha service class
  *
  * @param array $config An array of configuration parameters for the reCaptcha class
  * @return reCaptcha An instance of the reCaptcha class
  */
 public function loadReCaptcha(array $config = array())
 {
     if (empty($this->reCaptcha)) {
         if ($this->modx->loadClass('recaptcha.FormItReCaptcha', $this->config['modelPath'], true, true)) {
             $this->reCaptcha = new FormItReCaptcha($this->formit, $config);
         } else {
             $this->modx->log(modX::LOG_LEVEL_ERROR, '[FormIt] ' . $this->modx->lexicon('formit.recaptcha_err_load'));
             return false;
         }
     }
     return $this->reCaptcha;
 }
 /**
  * Verifies the authenticity of the provider
  *
  * @return boolean True if verified, xml if failed
  */
 public function verify()
 {
     $response = $this->request('verify', 'GET');
     if ($response->isError()) {
         $message = $response->getError();
         if ($this->xpdo->lexicon && $this->xpdo->lexicon->exists('provider_err_' . $message)) {
             $message = $this->xpdo->lexicon('provider_err_' . $message);
         }
         return $message;
     }
     $status = $response->toXml();
     return (bool) $status->verified;
 }
 /**
  * Send the notification
  *
  * @param quipComment $comment
  * @param array $properties
  * @return boolean
  */
 public function send(quipComment $comment, array $properties = array())
 {
     $this->xpdo->getService('mail', 'mail.modPHPMailer');
     if (!$this->xpdo->mail) {
         return false;
     }
     $email = $this->get('email');
     /* set unsubscription link */
     $unsubscribeSecretHash = 'One sees great things from the valley, only small things from the peak.';
     $hash = md5('quip.' . $unsubscribeSecretHash . $email . $this->get('createdon'));
     $properties['unsubscribeUrl'] = $comment->makeUrl('', array('quip_unsub' => $email, 'quip_uhsh' => $hash), array('scheme' => 'full'), false) . '#quip-success-' . $comment->get('idprefix');
     $properties['unsubscribeText'] = $this->xpdo->lexicon('quip.unsubscribe_text', array('unsubscribeUrl' => $properties['unsubscribeUrl']));
     $body = $this->xpdo->lexicon('quip.email_notify', $properties);
     $subject = $this->xpdo->lexicon('quip.email_notify_subject');
     $emailFrom = $this->xpdo->context->getOption('quip.emailsFrom', $this->xpdo->context->getOption('emailsender'));
     $emailReplyTo = $this->xpdo->context->getOption('quip.emailsReplyTo', $this->xpdo->context->getOption('emailsender'));
     if (empty($email) || strpos($email, '@') == false) {
         return false;
     }
     if ($this->xpdo->parser) {
         $this->xpdo->parser->processElementTags('', $body, true, false);
         $this->xpdo->parser->processElementTags('', $subject, true, false);
         $this->xpdo->parser->processElementTags('', $emailFrom, true, false);
         $this->xpdo->parser->processElementTags('', $emailReplyTo, true, false);
     }
     $this->xpdo->mail->set(modMail::MAIL_BODY, $body);
     $this->xpdo->mail->set(modMail::MAIL_FROM, $emailFrom);
     $this->xpdo->mail->set(modMail::MAIL_FROM_NAME, $this->xpdo->context->getOption('quip.emails_from_name', 'Quip'));
     $this->xpdo->mail->set(modMail::MAIL_SENDER, $emailFrom);
     $this->xpdo->mail->set(modMail::MAIL_SUBJECT, $subject);
     $this->xpdo->mail->address('to', $email);
     $this->xpdo->mail->address('reply-to', $emailReplyTo);
     $this->xpdo->mail->setHTML(true);
     $success = $this->xpdo->mail->send();
     $this->xpdo->mail->reset();
     return $success;
 }
 /**
  * Overrides modElement::remove to add custom error logging and fire
  * modX-specific events.
  *
  * {@inheritdoc}
  */
 public function remove(array $ancestors = array())
 {
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnTemplateVarBeforeRemove', array('templateVar' => &$this, 'cacheFlag' => true));
     }
     $removed = parent::remove($ancestors);
     if ($removed && $this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnTemplateVarRemove', array('templateVar' => &$this, 'cacheFlag' => true));
     } else {
         if (!$removed && !empty($this->xpdo->lexicon)) {
             $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->xpdo->lexicon('tv_err_remove') . $this->toArray());
         }
     }
     return $removed;
 }
 /**
  * Math field hook for anti-spam math input field.
  *
  * @access public
  * @param array $fields An array of cleaned POST fields
  * @return boolean True if email was successfully sent.
  */
 public function math(array $fields = array())
 {
     $mathField = $this->modx->getOption('mathField', $this->config, 'math');
     if (!isset($fields[$mathField])) {
         $this->errors[$mathField] = $this->modx->lexicon('formit.math_field_nf', array('field' => $mathField));
         return false;
     }
     if (empty($fields[$mathField])) {
         $this->errors[$mathField] = $this->modx->lexicon('formit.field_required', array('field' => $mathField));
         return false;
     }
     $op1Field = $this->modx->getOption('mathOp1Field', $this->config, 'op1');
     if (empty($fields[$op1Field])) {
         $this->errors[$mathField] = $this->modx->lexicon('formit.math_field_nf', array('field' => $op1Field));
         return false;
     }
     $op2Field = $this->modx->getOption('mathOp2Field', $this->config, 'op2');
     if (empty($fields[$op2Field])) {
         $this->errors[$mathField] = $this->modx->lexicon('formit.math_field_nf', array('field' => $op2Field));
         return false;
     }
     $operatorField = $this->modx->getOption('mathOperatorField', $this->config, 'operator');
     if (empty($fields[$operatorField])) {
         $this->errors[$mathField] = $this->modx->lexicon('formit.math_field_nf', array('field' => $operatorField));
         return false;
     }
     $answer = false;
     $op1 = (int) $fields[$op1Field];
     $op2 = (int) $fields[$op2Field];
     switch ($fields[$operatorField]) {
         case '+':
             $answer = $op1 + $op2;
             break;
         case '-':
             $answer = $op1 - $op2;
             break;
         case '*':
             $answer = $op1 * $op2;
             break;
     }
     $guess = (int) $fields[$mathField];
     $passed = (bool) ($guess == $answer);
     if (!$passed) {
         $this->addError($mathField, $this->modx->lexicon('formit.math_incorrect'));
     }
     return $passed;
 }
Example #13
0
 /**
  * Check for a custom error message, otherwise use a lexicon entry.
  * @param string $field
  * @param string $parameter
  * @param string $lexiconKey
  * @param array $properties
  * @return null|string
  */
 public function _getErrorMessage($field, $parameter, $lexiconKey, array $properties = array())
 {
     if (!empty($this->formit->config[$field . '.' . $parameter])) {
         $message = $this->formit->config[$field . '.' . $parameter];
         $this->modx->lexicon->set($lexiconKey, $message);
         $this->modx->lexicon($lexiconKey, $properties);
     } else {
         if (!empty($this->formit->config[$parameter])) {
             $message = $this->formit->config[$parameter];
             $this->modx->lexicon->set($lexiconKey, $message);
             $this->modx->lexicon($lexiconKey, $properties);
         } else {
             $message = $this->modx->lexicon($lexiconKey, $properties);
         }
     }
     return $message;
 }
Example #14
0
 /**
  * Sends notification to all watchers of this thread saying a new post has been made.
  *
  * @param quipComment $comment A reference to the actual comment
  * @return boolean True if successful
  */
 public function notify(quipComment &$comment)
 {
     if (!$this->_loadLexicon()) {
         return false;
     }
     $this->xpdo->lexicon->load('quip:emails');
     /* get the poster's email address */
     $posterEmail = false;
     $user = $comment->getOne('Author');
     if ($user) {
         $profile = $user->getOne('Profile');
         if ($profile) {
             $posterEmail = $profile->get('email');
         }
     }
     /* get email body/subject */
     $properties = $comment->toArray();
     $properties['url'] = $comment->makeUrl('', array(), array('scheme' => 'full'));
     $body = $this->xpdo->lexicon('quip.email_notify', $properties);
     $subject = $this->xpdo->lexicon('quip.email_notify_subject');
     /* send notifications */
     $success = true;
     $notifyEmails = $this->get('notify_emails');
     $emails = explode(',', $notifyEmails);
     /* send notifications to notify_emails subjects */
     if (!empty($emails)) {
         $this->sendEmail($subject, $body, $emails);
     }
     /* now send to notified users */
     $notifiees = $this->getMany('Notifications');
     /** @var quipCommentNotify $notification */
     foreach ($notifiees as $notification) {
         $email = $notification->get('email');
         /* remove invalid emails */
         if (empty($email) || strpos($email, '@') == false) {
             $notification->remove();
             continue;
         }
         /* don't notify the poster, since they posted the comment. */
         if ($posterEmail == $email) {
             continue;
         }
         $notification->send($comment, $properties);
     }
     return $success;
 }
 /**
  * @param $method
  * @param array $params
  *
  * @return string
  */
 public function fenomFunction($method, array $params)
 {
     if (empty($params[0])) {
         return '';
     }
     $result = '';
     switch ($method) {
         case 'lexicon':
             $key = array_shift($params);
             if (!empty($params[0]) && is_array($params[0])) {
                 $properties = $params[0];
                 $topic = !empty($properties['topic']) ? $properties['topic'] : 'default';
                 $namespace = !empty($properties['namespace']) ? $properties['namespace'] : 'core';
                 $language = !empty($properties['language']) ? $properties['language'] : $this->modx->getOption('cultureKey', null, 'en');
                 $this->modx->lexicon->load($language . ':' . $namespace . ':' . $topic);
             }
             $placeholders = !empty($params[1]) && is_array($params[1]) ? $params[1] : array();
             $result = $this->modx->lexicon($key, $placeholders);
             break;
         case 'url':
             $id = trim(array_shift($params), '[]~');
             if (is_numeric($id)) {
                 $context = $this->modx->context->get('key');
                 $scheme = $this->modx->getOption('link_tag_scheme', null, -1);
                 $options = array();
                 if (!empty($params[0]) && is_array($params[0])) {
                     $options = $params[0];
                     if (isset($options['context'])) {
                         $context = $options['context'];
                         unset($options['context']);
                     }
                     if (isset($options['scheme'])) {
                         $scheme = $options['scheme'];
                         unset($options['scheme']);
                     }
                 }
                 $args = !empty($params[1]) && is_array($params[1]) ? $params[1] : array();
                 $result = $this->modx->makeUrl($id, $context, $args, $scheme, $options);
             }
             break;
     }
     return $result;
 }
Example #16
0
 /**
  * Run the processor, returning a modProcessorResponse object.
  * @return modProcessorResponse
  */
 public function run()
 {
     if (!$this->checkPermissions()) {
         $o = $this->failure($this->modx->lexicon('permission_denied'));
     } else {
         $topics = $this->getLanguageTopics();
         foreach ($topics as $topic) {
             $this->modx->lexicon->load($topic);
         }
         $initialized = $this->initialize();
         if ($initialized !== true) {
             $o = $this->failure($initialized);
         } else {
             $o = $this->process();
         }
     }
     $response = new modProcessorResponse($this->modx, $o);
     return $response;
 }
 /**
  * This runs each time the tree is drawn.
  * @param array $node
  * @return array
  */
 public function prepareTreeNode(array $node = array())
 {
     $this->xpdo->lexicon->load('articles:default');
     $menu = array();
     $idNote = $this->xpdo->hasPermission('tree_show_resource_ids') ? ' <span dir="ltr">(' . $this->id . ')</span>' : '';
     // Template ID should 1st default to the container settings for articleTemplate,
     // then to system settings for articles.default_article_template.
     // getContainerSettings() is not in scope here.
     // System Default
     $template_id = $this->getOption('articles.default_article_template');
     // Attempt to override for this container
     $container = $this->xpdo->getObject('modResource', $this->id);
     if ($container) {
         $props = $container->get('properties');
         if ($props) {
             if (isset($props['articles']['articleTemplate']) && !empty($props['articles']['articleTemplate'])) {
                 $template_id = $props['articles']['articleTemplate'];
             }
         }
     }
     $menu[] = array('text' => '<b>' . $this->get('pagetitle') . '</b>' . $idNote, 'handler' => 'Ext.emptyFn');
     $menu[] = '-';
     $menu[] = array('text' => $this->xpdo->lexicon('articles.articles_manage'), 'handler' => 'this.editResource');
     $menu[] = array('text' => $this->xpdo->lexicon('articles.articles_write_new'), 'handler' => "function(itm,e) { \n\t\t\t\tvar at = this.cm.activeNode.attributes;\n\t\t        var p = itm.usePk ? itm.usePk : at.pk;\n\t\n\t            Ext.getCmp('modx-resource-tree').loadAction(\n\t                'a='+MODx.action['resource/create']\n\t                + '&class_key='+itm.classKey\n\t                + '&parent='+p\n\t                + '&template=" . $template_id . "'\n\t                + (at.ctx ? '&context_key='+at.ctx : '')\n                );\n        \t}");
     $menu[] = array('text' => $this->xpdo->lexicon('articles.container_duplicate'), 'handler' => 'function(itm,e) { itm.classKey = "ArticlesContainer"; this.duplicateResource(itm,e); }');
     $menu[] = '-';
     if ($this->get('published')) {
         $menu[] = array('text' => $this->xpdo->lexicon('articles.container_unpublish'), 'handler' => 'this.unpublishDocument');
     } else {
         $menu[] = array('text' => $this->xpdo->lexicon('articles.container_publish'), 'handler' => 'this.publishDocument');
     }
     if ($this->get('deleted')) {
         $menu[] = array('text' => $this->xpdo->lexicon('articles.container_undelete'), 'handler' => 'this.undeleteDocument');
     } else {
         $menu[] = array('text' => $this->xpdo->lexicon('articles.container_delete'), 'handler' => 'this.deleteDocument');
     }
     $menu[] = '-';
     $menu[] = array('text' => $this->xpdo->lexicon('articles.articles_view'), 'handler' => 'this.preview');
     $node['menu'] = array('items' => $menu);
     $node['hasChildren'] = true;
     return $node;
 }
Example #18
0
 public function checkBlocked()
 {
     /* blocked until */
     $blockedUntil = $this->processor->getProperty('blockeduntil');
     if (!empty($blockedUntil)) {
         $blockedUntil = str_replace('-', '/', $blockedUntil);
         if (!($blockedUntil = strtotime($blockedUntil))) {
             $this->processor->addFieldError('blockeduntil', $this->modx->lexicon('user_err_not_specified_blockeduntil'));
         }
         $this->processor->setProperty('blockeduntil', $blockedUntil);
         $this->profile->set('blockeduntil', $blockedUntil);
     }
     /* blocked after */
     $blockedAfter = $this->processor->getProperty('blockedafter');
     if (!empty($blockedAfter)) {
         $blockedAfter = str_replace('-', '/', $blockedAfter);
         if (!($blockedAfter = strtotime($blockedAfter))) {
             $this->processor->addFieldError('blockedafter', $this->modx->lexicon('user_err_not_specified_blockedafter'));
         }
         $this->processor->setProperty('blockedafter', $blockedAfter);
         $this->profile->set('blockedafter', $blockedAfter);
     }
 }
 /**
  * Use this in your extended Resource class to return a translatable name for the Resource Type.
  * @return string
  */
 public function getResourceTypeName()
 {
     $className = $this->_class;
     if ($className == 'modDocument') {
         $className = 'document';
     }
     return $this->xpdo->lexicon($className);
 }
Example #20
0
    if (!$modx->user->hasSessionContext('mgr')) {
        die('Unauthorized Access');
    }
}
// include 'mycomponentproject.class.php';
$modx->lexicon->load('mycomponent:default');
require_once $modx->getOption('mc.core_path', null, $modx->getOption('core_path') . 'components/mycomponent/') . 'model/mycomponent/mycomponentproject.class.php';
$project = new MyComponentProject($modx);
$props = isset($scriptProperties) ? $scriptProperties : array();
$project->init($props);
$project->exportComponent(false);
$output = $project->helpers->getOutput();
// echo print_r(ObjectAdapter::$myObjects, true);
$output .= "\n\n" . $modx->lexicon('mc_initial_memory_used') . ': ' . round($mem_usage / 1048576, 2) . ' ' . $modx->lexicon('mc_megabytes');
$mem_usage = memory_get_usage();
$peak_usage = memory_get_peak_usage(true);
$output .= "\n" . $modx->lexicon('mc_final_memory_used') . ': ' . round($mem_usage / 1048576, 2) . ' ' . $modx->lexicon('mc_megabytes');
$output .= "\n" . $modx->lexicon('mc_peak_memory_used') . ': ' . round($peak_usage / 1048576, 2) . ' ' . $modx->lexicon('mc_megabytes');
/* report how long it took */
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
$output .= "\n" . $modx->lexicon('mc_total_time') . ': ' . $totalTime;
if ($cliMode) {
    echo $output;
} else {
    return $output;
}
Example #21
0
 /**
  * Prepare the comment for rendering
  * 
  * @param array $properties
  * @param int $idx
  * @return array
  */
 public function prepare(array $properties = array(), $idx)
 {
     $alt = $idx % 2;
     $commentArray = $this->toArray();
     $commentArray['children'] = '';
     $commentArray['alt'] = $alt ? $this->getOption('altRowCss', $properties) : '';
     $commentArray['createdon'] = strftime($this->getOption('dateFormat', $properties), strtotime($this->get('createdon')));
     $commentArray['url'] = $this->makeUrl();
     $commentArray['idx'] = $idx;
     $commentArray['threaded'] = $this->getOption('threaded', $properties, true);
     $commentArray['depth'] = $this->get('depth');
     $commentArray['depth_margin'] = $this->getOption('useMargins', $properties, false) ? (int) ($this->getOption('threadedPostMargin', $properties, '15') * $this->get('depth')) + 7 : '';
     $commentArray['cls'] = $this->getOption('rowCss', $properties, '') . ($this->get('approved') ? '' : ' ' . $this->getOption('unapprovedCls', $properties, 'quip-unapproved'));
     $commentArray['olCls'] = $this->getOption('olCss', $properties, '');
     if ($this->getOption('useGravatar', $properties, true)) {
         $commentArray['md5email'] = md5($this->get('email'));
         $commentArray['gravatarIcon'] = $this->getOption('gravatarIcon', $properties, 'mm');
         $commentArray['gravatarSize'] = $this->getOption('gravatarSize', $properties, 60);
         $urlsep = $this->xpdo->context->getOption('xhtml_urls', true) ? '&amp;' : '&';
         $commentArray['gravatarUrl'] = $this->getOption('gravatarUrl', $properties) . $commentArray['md5email'] . '?s=' . $commentArray['gravatarSize'] . $urlsep . 'd=' . $commentArray['gravatarIcon'];
     } else {
         $commentArray['gravatarUrl'] = '';
     }
     /* check for auth */
     if ($this->hasAuth) {
         /* allow removing of comment if moderator or own comment */
         $commentArray['allowRemove'] = $this->getOption('allowRemove', $properties, true);
         if ($commentArray['allowRemove']) {
             if ($this->isModerator) {
                 /* Always allow remove for moderators */
                 $commentArray['allowRemove'] = true;
             } else {
                 if ($this->get('author') == $this->xpdo->user->get('id')) {
                     /* if not moderator but author of post, check for remove
                      * threshold, which prevents removing comments after X minutes
                      */
                     $removeThreshold = $this->getOption('removeThreshold', $properties, 3);
                     if (!empty($removeThreshold)) {
                         $diff = time() - strtotime($this->get('createdon'));
                         if ($diff > $removeThreshold * 60) {
                             $commentArray['allowRemove'] = false;
                         }
                     }
                 }
             }
         }
         $commentArray['reported'] = !empty($_GET['reported']) && $_GET['reported'] == $this->get('id') ? 1 : '';
         if ($this->get('author') == $this->xpdo->user->get('id') || $this->isModerator) {
             $params = $this->xpdo->request->getParameters();
             $params['quip_comment'] = $this->get('id');
             $params[$this->getOption('removeAction', $properties, 'quip-remove')] = true;
             $commentArray['removeUrl'] = $this->makeUrl('', $params, null, false);
             $commentArray['options'] = $this->xpdo->quip->getChunk($this->getOption('tplCommentOptions', $properties), $commentArray);
         } else {
             $commentArray['options'] = '';
         }
         if ($this->getOption('allowReportAsSpam', $properties, true)) {
             $params = $this->xpdo->request->getParameters();
             $params['quip_comment'] = $this->get('id');
             $params[$this->getOption('reportAction', $properties, 'quip-report')] = true;
             $commentArray['reportUrl'] = $this->makeUrl('', $params, null, false);
             $commentArray['report'] = $this->xpdo->quip->getChunk($this->getOption('tplReport', $properties), $commentArray);
         }
     } else {
         $commentArray['report'] = '';
     }
     /* get author display name */
     $authorTpl = $this->getOption('authorTpl', $properties, 'quipAuthorTpl');
     $nameField = $this->getOption('nameField', $properties, 'username');
     $commentArray['authorName'] = '';
     if (empty($commentArray[$nameField])) {
         $commentArray['authorName'] = $this->xpdo->quip->getChunk($authorTpl, array('name' => $this->getOption('showAnonymousName', false) ? $this->getOption('anonymousName', $this->xpdo->lexicon('quip.anonymous')) : $commentArray['name'], 'url' => ''));
     } else {
         $commentArray['authorName'] = $this->xpdo->quip->getChunk($authorTpl, array('name' => $commentArray[$nameField], 'url' => ''));
     }
     if ($this->getOption('showWebsite', $properties, true) && !empty($commentArray['website'])) {
         $commentArray['authorName'] = $this->xpdo->quip->getChunk($authorTpl, array('name' => $commentArray[$nameField], 'url' => $commentArray['website']));
     }
     if ($this->getOption('threaded', $properties, true) && $this->getOption('stillOpen', $properties, true) && $this->get('depth') < $this->getOption('maxDepth', $properties, 10) && $this->get('approved') && !$this->getOption('closed', $properties, false)) {
         if (!$this->getOption('requireAuth', $properties, false) || $this->hasAuth) {
             $params = $this->xpdo->request->getParameters();
             $params['quip_thread'] = $this->get('thread');
             $params['quip_parent'] = $this->get('id');
             $commentArray['replyUrl'] = $this->xpdo->makeUrl($this->getOption('replyResourceId', $properties, 1), '', $params);
         }
     } else {
         $commentArray['replyUrl'] = '';
     }
     return $commentArray;
 }
$helper->sendLog(modX::LOG_LEVEL_INFO, "\n" . $modx->lexicon('mc_project') . ': ' . $currentProject);
$helper->sendLog(modX::LOG_LEVEL_INFO, $modx->lexicon('mc_action') . ': ' . $modx->lexicon('mc_build'));
$helper->sendLog(modX::LOG_LEVEL_INFO, $modx->lexicon('mc_created_package') . ': ' . PKG_NAME_LOWER . '-' . PKG_VERSION . '-' . PKG_RELEASE);
$helper->sendLog(modX::LOG_LEVEL_INFO, "\n" . $modx->lexicon('mc_created_namespace') . ': ' . PKG_NAME_LOWER);
/* load builder */
$modx->setLogLevel(modX::LOG_LEVEL_ERROR);
$modx->loadClass('transport.modPackageBuilder', '', false, true);
$builder = new modPackageBuilder($modx);
$builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE);
$assetsPath = $hasAssets ? '{assets_path}components/' . PKG_NAME_LOWER . '/' : '';
$builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/', $assetsPath);
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
/* Transport Contexts */
if ($hasContexts) {
    $contexts = (include $sources['data'] . 'transport.contexts.php');
    if (!is_array($contexts)) {
        $helper->sendLog(modX::LOG_LEVEL_ERROR, $modx->lexicon('mc_contexts_not_an_array'));
    } else {
        $attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false);
        foreach ($contexts as $context) {
            $vehicle = $builder->createVehicle($context, $attributes);
            $builder->putVehicle($vehicle);
        }
        $helper->sendLog(modX::LOG_LEVEL_INFO, $modx->lexicon('mc_packaged') . ' ' . count($contexts) . ' ' . $modx->lexicon('mc_new_contexts'));
        unset($contexts, $context, $attributes);
    }
}
/* Transport Resources */
if ($hasResources) {
    $resources = (include $sources['data'] . 'transport.resources.php');
    if (!is_array($resources)) {
        $helper->sendLog(modX::LOG_LEVEL_ERROR, $modx->lexicon('mc_resources_not_an_array'));
    if (!is_dir(MODX_BASE_PATH . 'setup')) {
        MODXInstaller::quit('File Copy Failed');
    }
    MODXInstaller::removeFolder($tempDir, true);
    /* Clear cache files but not cache folder */
    $path = MODX_CORE_PATH . 'cache';
    if (is_dir($path)) {
        MODXInstaller::removeFolder($path, false);
    }
    unlink(basename(__FILE__));
    /* Log upgrade in Manager Actions log */
    include MODX_CORE_PATH . 'model/modx/modx.class.php';
    $modx = new modX();
    $modx->initialize('web');
    $modx->lexicon->load('core:default');
    $modx->logManagerAction('Upgrade MODX', 'modWorkspace', $modx->lexicon('version') . ' ' . $_GET['modx'], $_GET['userId']);
    $modx = null;
    /* Forward to Setup */
    header('Location: ' . $rowInstall['location']);
} else {
    $ItemGrid = array();
    foreach ($InstallData as $ver => $item) {
        $ItemGrid[$item['tree']][$ver] = $item;
    }
    /* Display the Form */
    echo '
<!DOCTYPE html>
<html>
<head>
    <title>UpgradeMODX</title>
    <meta charset="utf-8">
 /**
  * @param $message
  *
  * @return string
  */
 public function failure($message)
 {
     return $this->response($this->modx->lexicon($message), array(), false);
 }
Example #25
0
<?php

if (!defined('MODX_API_MODE')) {
    define('MODX_API_MODE', false);
}
include dirname(dirname(dirname(dirname(__FILE__)))) . '/config.core.php';
if (!defined('MODX_CORE_PATH')) {
    define('MODX_CORE_PATH', dirname(dirname(dirname(dirname(__FILE__)))) . '/core/');
}
include_once MODX_CORE_PATH . "model/modx/modx.class.php";
$modx = new modX();
$modx->initialize('mgr');
$modx->lexicon->load('core:default');
if (!$modx->user->isAuthenticated('mgr')) {
    echo $modx->lexicon('permission_denied');
    exit;
}
$modx->getService('error', 'error.modError');
$modx->getService('smarty', 'smarty.modSmarty');
$templates = array('home');
//$modx->smarty->assign('var', $results);
$modx->smarty->caching = false;
$modx->smarty->template_dir = $modx->getOption('core_path') . 'components/tag_manager2/templates/';
$template_name = isset($_GET['a']) && in_array($_GET['a'], $templates) ? $_GET['a'] : 'home';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
Example #26
0
 /**
  * Set the page title of your page by overriding this method
  * @return string
  */
 public function getPageTitle()
 {
     return $this->modx->lexicon('handyman');
 }
 /**
  * Translate any needed properties
  * @param array $properties
  * @return array
  */
 public function prepareProperties(array $properties = array())
 {
     foreach ($properties as &$property) {
         if (!empty($property['lexicon'])) {
             $this->xpdo->lexicon->load($property['lexicon']);
         }
         if (!empty($property['name'])) {
             $property['name_trans'] = $this->xpdo->lexicon($property['name']);
         }
         if (!empty($property['desc'])) {
             $property['desc_trans'] = $this->xpdo->lexicon($property['desc']);
         }
         if (!empty($property['options'])) {
             foreach ($property['options'] as &$option) {
                 if (empty($option['text']) && !empty($option['name'])) {
                     $option['text'] = $option['name'];
                     unset($option['name']);
                 }
                 if (empty($option['value']) && !empty($option[0])) {
                     $option['value'] = $option[0];
                     unset($option[0]);
                 }
                 $option['name'] = $this->xpdo->lexicon($option['text']);
             }
         }
     }
     return $properties;
 }
Example #28
0
 /**
  * @param $key
  * @param array $params
  * @param string $language
  *
  * @return null|string
  */
 public function lexicon($key, $params = array(), $language = '')
 {
     return $this->modx->lexicon($key, $params, $language);
 }
Example #29
0
 /**
  * @param array $data
  *
  * @return array|string
  */
 public function createPayment(array $data)
 {
     if (!$this->modx->user->isAuthenticated($this->modx->context->key)) {
         return $this->ms2->error($this->modx->lexicon('ms2_profile_err_auth'));
     }
     // Call system event
     $response = $this->ms2->invokeEvent('msOnSubmitOrder', array('data' => $data, 'order' => $this->ms2->order));
     if (!$response['success']) {
         return $this->ms2->error($response['message']);
     }
     if (!empty($response['data']['data'])) {
         $data = array_merge($data, $response['data']['data']);
         $this->ms2->order->set($data);
     }
     // Check required fields
     $errors = array();
     if (empty($data['sum']) || $data['sum'] < $this->config['minSum']) {
         $errors['sum'] = $this->modx->lexicon('ms2_profile_err_min_sum', array('min_sum' => $this->config['minSum']));
     } elseif (!empty($maxSum) && $data['sum'] > $this->config['maxSum']) {
         $errors['sum'] = $this->modx->lexicon('ms2_profile_err_max_sum', array('max_sum' => $this->config['maxSum']));
     }
     if (empty($data['payment'])) {
         $errors['payment'] = $this->modx->lexicon('ms2_profile_err_payment', array('min_sum' => $this->config['minSum']));
     }
     if (!empty($errors)) {
         return $this->ms2->error($this->modx->lexicon('ms2_profile_err_form'), $errors);
     }
     // Create new order
     /** @var msOrder $order */
     $order = $this->modx->newObject('msOrder', array('user_id' => $this->modx->user->id, 'createdon' => date('Y-m-d H:i:s'), 'num' => $this->ms2->order->getnum(), 'delivery' => 0, 'payment' => $data['payment'], 'cart_cost' => $data['sum'], 'weight' => 0, 'delivery_cost' => 0, 'cost' => $data['sum'], 'status' => 0, 'context' => $this->ms2->config['ctx'], 'properties' => array('account_charge' => true)));
     $products = array($this->modx->newObject('msOrderProduct', array('product_id' => 0, 'name' => $this->modx->lexicon('ms2_profile_charge'), 'price' => $data['sum'], 'cost' => $data['sum'])));
     $order->addMany($products);
     $response = $this->ms2->invokeEvent('msOnBeforeCreateOrder', array('msOrder' => $order, 'order' => $this->ms2->order));
     if (!$response['success']) {
         return $this->ms2->error($response['message']);
     }
     if ($order->save()) {
         $response = $this->ms2->invokeEvent('msOnCreateOrder', array('msOrder' => $order, 'order' => $this->ms2->order));
         if (!$response['success']) {
             return $this->ms2->error($response['message']);
         }
         if (empty($_SESSION['minishop2']['orders'])) {
             $_SESSION['minishop2']['orders'] = array();
         }
         $_SESSION['minishop2']['orders'][] = $order->get('id');
         // Trying to set status "new"
         $response = $this->ms2->changeOrderStatus($order->get('id'), 1);
         if ($response !== true) {
             return $this->ms2->error($response, array('msorder' => $order->get('id')));
         } elseif ($payment = $this->modx->getObject('msPayment', array('id' => $order->get('payment'), 'active' => 1))) {
             $response = $payment->send($order);
             if (!empty($response['data']['redirect'])) {
                 $this->modx->sendRedirect($response['data']['redirect']);
             } elseif (!empty($response['data']['msorder'])) {
                 $this->modx->sendRedirect($this->modx->context->makeUrl($this->modx->resource->id, array('msorder' => $response['data']['msorder'])));
             } else {
                 $this->modx->sendRedirect($this->modx->context->makeUrl($this->modx->resource->id));
             }
         } else {
             $this->modx->sendRedirect($this->modx->context->makeUrl($this->modx->resource->id, array('msorder' => $response['data']['msorder'])));
         }
     }
 }
Example #30
0
 /**
  * This method returns an success of the order
  *
  * @param string $message A lexicon key for success message
  * @param array $data.Additional data, for example cart status
  * @param array $placeholders Array with placeholders for lexicon entry
  *
  * @return array|string $response
  */
 public function success($message = '', $data = array(), $placeholders = array())
 {
     $response = array('success' => true, 'message' => $this->modx->lexicon($message, $placeholders), 'data' => $data);
     return $this->config['json_response'] ? $this->modx->toJSON($response) : $response;
 }