/**
  * Upload file
  *
  * @param $data
  * @param string $class
  *
  * @return array|string
  */
 public function fileUpload($data)
 {
     if (!$this->authenticated) {
         return $this->error('ms2galleryform_err_access_denied');
     }
     /** @var modProcessorResponse $response */
     $response = $this->modx->runProcessor('web/gallery/upload', $data, array('processors_path' => $this->config['corePath'] . 'processors/'));
     if ($response->isError()) {
         return $this->error($response->getMessage());
     }
     $file = $response->getObject();
     $file['size'] = round($file['properties']['size'] / 1024, 2);
     $tpl = $file['type'] == 'image' ? $this->config['tplImage'] : $this->config['tplFile'];
     $html = $this->modx->getChunk($tpl, $file);
     return $this->success('', $html);
 }
 /**
  * Main processing method
  *
  * @param $data
  *
  * @return string
  */
 public function uploadFile($data)
 {
     if (!$this->checkAuth()) {
         return 'Wrong auth';
     }
     $fileParts = pathinfo($data['name']);
     $data['extension'] = strtolower($fileParts['extension']);
     // Main verifications
     if (!($file = is_uploaded_file($data['tmp_name']))) {
         return $this->failure('uf_err_nofile');
     } else {
         if (!in_array($data['extension'], $this->config['fileExtensions'])) {
             return $this->failure('uf_err_extension');
         } else {
             if ($data['size'] > $this->config['maxFilesize']) {
                 return $this->failure('uf_err_size');
             }
         }
     }
     // Save image
     $base_url = $this->modx->getOption('url_scheme', null, 'http://', true);
     $base_url .= $this->modx->getOption('http_host');
     if (in_array($data['extension'], $this->config['imageExtensions'])) {
         if ($file = $this->saveImage($data)) {
             $arr = array('image' => strpos($file['image'], '://') === false ? $base_url . '/' . ltrim($file['image'], '/') : $file['image'], 'thumb' => !empty($file['thumb']) ? strpos($file['thumb'], '://') === false ? $base_url . '/' . ltrim($file['thumb'], '/') : $file['thumb'] : '');
             return $this->success($this->modx->getChunk($this->config['tplImage'], $arr));
         }
     } else {
         if ($file = $this->saveFile($data)) {
             $arr = array('file' => strpos($file['file'], '://') === false ? $base_url . '/' . ltrim($file['file'], '/') : $file['file']);
             return $this->success($this->modx->getChunk($this->config['tplFile'], $arr));
         }
     }
     return $this->failure('uf_err_unknown');
 }
 /**
  * Add an element to the list
  *
  * @param integer $docId
  * @return bool|integer
  */
 private function add($docId)
 {
     $found = 0;
     $newElement = array();
     $newElement['rememberId'] = $docId;
     if (!$this->getOption('packagename')) {
         // no packagename -> resource
         $resource = $this->modx->getObject('modResource', array('id' => $docId));
         $tvs = array();
         $templateVars =& $resource->getMany('TemplateVars');
         foreach ($templateVars as $templateVar) {
             $tvs[$this->getOption('tvPrefix') . $templateVar->get('name')] = $templateVar->renderOutput($resource->get('id'));
         }
         $row = array_merge($resource->toArray(), $tvs);
     } else {
         $packagepath = $this->modx->getOption('core_path') . 'components/' . $this->getOption('packagename') . '/';
         $modelpath = $packagepath . 'model/';
         $this->modx->addPackage($this->getOption('packagename'), $modelpath);
         $resource = $this->modx->getObject($this->getOption('classname'), array($this->getOption('keyname') => $docId));
         if ($resource) {
             $joinvalues = array();
             $joinoption = $this->getOption('joins');
             if ($joinoption) {
                 foreach ($joinoption as $join) {
                     $values = $resource->getOne($join);
                     $joinvalues[$join] = $values->toArray();
                 }
             }
             $row = array_merge($joinvalues, $resource->toArray());
         } else {
             $this->modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not retreive an object with key "' . $this->getOption('keyname') . '" and value "' . $docId . '"', '', 'RememberThis');
             return false;
         }
     }
     $newElement['identifier'] = $row[$this->getOption('keyname')];
     $newElement['itemtitle'] = $this->modx->getChunk($this->getOption('itemTitleTpl'), $row);
     foreach ($_SESSION['rememberThis'] as &$element) {
         if (!count(array_diff_assoc($element['element'], $newElement))) {
             $found = 1;
         }
     }
     if (!$found) {
         $_SESSION['rememberThis'][] = array('element' => $newElement);
         if ($this->getOption('useCookie')) {
             $this->setCookie();
         }
         return key($_SESSION['rememberThis']);
     } else {
         return false;
     }
 }
示例#4
0
 /**
  * Get a template chunk. All chunks retrieved by this function are
  * cached in $modx->chunkieCache for later reusage.
  *
  * @access public
  * @param string $tpl The name of a MODX chunk (could be prefixed by
  * @FILE, @CODE or @CHUNK). Chunknames starting with '@FILE' are
  * loading a chunk from the filesystem (prefixed by $basepath).
  * Chunknames starting with '@CODE' contain the template code itself.
  * @return string The template chunk.
  */
 public function getTemplateChunk($tpl)
 {
     switch (TRUE) {
         case substr($tpl, 0, 5) == '@FILE':
             $filename = trim(substr($tpl, 5), ' :');
             if (!isset($this->modx->chunkieCache['@FILE'])) {
                 $this->modx->chunkieCache['@FILE'] = array();
             }
             if (!empty($filename) && !array_key_exists($filename, $this->modx->chunkieCache['@FILE'])) {
                 if (file_exists($this->options['basepath'] . $filename)) {
                     $template = file_get_contents($this->options['basepath'] . $filename);
                 } else {
                     $template = '';
                 }
                 $this->modx->chunkieCache['@FILE'][$filename] = $template;
             } else {
                 $template = !empty($filename) ? $this->modx->chunkieCache['@FILE'][$filename] : '';
             }
             break;
         case substr($tpl, 0, 5) == '@CODE':
             $template = trim(substr($tpl, 5), ' :');
             break;
         default:
             if (substr($tpl, 0, 6) == '@CHUNK') {
                 $chunkname = trim(substr($tpl, 6), ' :');
             } else {
                 $chunkname = $tpl;
             }
             if (!isset($this->modx->chunkieCache['@CHUNK'])) {
                 $this->modx->chunkieCache['@CHUNK'] = array();
             }
             if (!empty($chunkname) && !array_key_exists($chunkname, $this->modx->chunkieCache['@CHUNK'])) {
                 $chunk = $this->modx->getChunk($chunkname);
                 $template = $chunk ? $chunk : $chunkname;
                 $this->modx->chunkieCache['@CHUNK'][$chunkname] = $template;
             } else {
                 $template = !empty($chunkname) ? $this->modx->chunkieCache['@CHUNK'][$chunkname] : '';
             }
             break;
     }
     return $template;
 }
    /**
     * Get the call for the RSS feed
     * @return string
     */
    public function getRssCall()
    {
        $settings = $this->getContainerSettings();
        $content = '[[!getArchives?
          &pageVarKey=`page`
          &parents=`' . $this->get('id') . '`
          &where=`{"class_key":"Article","searchable":1}`
          &limit=`' . $this->xpdo->getOption('rssItems', $settings, 10) . '`
          &showHidden=`1`
          &includeContent=`1`
          &includeTVs=`1`
          &processTVs=`1`
          &sortby=`' . $this->xpdo->getOption('sortBy', $settings, 'publishedon') . '`
          &sortdir=`' . $this->xpdo->getOption('sortDir', $settings, 'DESC') . '`

          &tagKey=`articlestags`
          &tagSearchType=`contains`
          &makeArchive=`0`
          &cache=`0`
          &tpl=`' . $this->xpdo->getOption('tplRssItem', $settings, 'sample.ArticlesRssItem') . '`
        ]]';
        $content = $this->xpdo->getChunk($this->xpdo->getOption('tplRssFeed', $settings, 'sample.ArticlesRss'), array('content' => $content, 'year' => date('Y')));
        return $content;
    }
 /**
  * Process bindings assigned to a template variable.
  *
  * @access public
  * @param string $value The value specified from the binding.
  * @param integer $resourceId The resource in which the TV is assigned.
  * @param boolean $preProcess Whether or not to process certain bindings.
  * @return string The processed value.
  */
 public function processBindings($value = '', $resourceId = 0, $preProcess = true)
 {
     $bdata = $this->getBindingDataFromValue($value);
     if (empty($bdata['cmd'])) {
         return $value;
     }
     $modx =& $this->xpdo;
     if (empty($modx->resource)) {
         if (!empty($resourceId)) {
             $modx->resource = $modx->getObject('modResource', $resourceId);
         }
         if (empty($modx->resource) || empty($resourceId)) {
             $modx->resource = $modx->newObject('modResource');
             $modx->resource->set('id', 0);
         }
     }
     $cmd = $bdata['cmd'];
     $param = !empty($bdata['param']) ? $bdata['param'] : null;
     switch ($cmd) {
         case 'FILE':
             if ($preProcess) {
                 $output = $this->processFileBinding($param);
             }
             break;
         case 'CHUNK':
             /* retrieve a chunk and process it's content */
             if ($preProcess) {
                 $output = $this->xpdo->getChunk($param);
             }
             break;
         case 'RESOURCE':
         case 'DOCUMENT':
             /* retrieve a document and process it's content */
             if ($preProcess) {
                 $query = $this->xpdo->newQuery('modResource', array('id' => (int) $param, 'deleted' => false));
                 $query->select('content');
                 if ($query->prepare() && $query->stmt->execute()) {
                     $output = $query->stmt->fetch(PDO::FETCH_COLUMN);
                 } else {
                     $output = 'Unable to locate resource ' . $param;
                 }
             }
             break;
         case 'SELECT':
             /* selects a record from the cms database */
             if ($preProcess) {
                 $dbtags = array();
                 if ($modx->resource && $modx->resource instanceof modResource) {
                     $dbtags = $modx->resource->toArray();
                 }
                 $dbtags['DBASE'] = $this->xpdo->getOption('dbname');
                 $dbtags['PREFIX'] = $this->xpdo->getOption('table_prefix');
                 foreach ($dbtags as $key => $pValue) {
                     $param = str_replace('[[+' . $key . ']]', $pValue, $param);
                 }
                 $stmt = $this->xpdo->query('SELECT ' . $param);
                 if ($stmt && $stmt instanceof PDOStatement) {
                     $data = '';
                     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
                         $col = '';
                         if (isset($row[1])) {
                             $col = $row[0] . '==' . $row[1];
                         } else {
                             $col = $row[0];
                         }
                         $data .= (!empty($data) ? '||' : '') . $col;
                     }
                     $stmt->closeCursor();
                 }
                 $output = $data;
             }
             break;
         case 'EVAL':
             /* evaluates text as php codes return the results */
             if ($preProcess) {
                 $output = eval($param);
             }
             break;
         case 'INHERIT':
             if ($preProcess) {
                 $output = $this->processInheritBinding($param, $resourceId);
             } else {
                 $output = $value;
             }
             break;
         case 'DIRECTORY':
             $path = $this->xpdo->getOption('base_path') . $param;
             if (substr($path, -1, 1) != '/') {
                 $path .= '/';
             }
             if (!is_dir($path)) {
                 break;
             }
             $files = array();
             $invalid = array('.', '..', '.svn', '.git', '.DS_Store');
             foreach (new DirectoryIterator($path) as $file) {
                 if (!$file->isReadable()) {
                     continue;
                 }
                 $basename = $file->getFilename();
                 if (!in_array($basename, $invalid)) {
                     $files[] = "{$basename}=={$param}/{$basename}";
                 }
             }
             asort($files);
             $output = implode('||', $files);
             break;
         default:
             $output = $value;
             break;
     }
     /* support for nested bindings */
     return is_string($output) && $output != $value ? $this->processBindings($output) : $output;
 }
示例#7
0
 /** @inheritdoc} */
 public function getWrapper()
 {
     return $this->modx->getChunk($this->config['tplOuter'], $this->config);
 }
示例#8
0
文件: roxy.php 项目: kipps/sri-lanka
<?php

//initialise MODx
require_once dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . "/config.core.php";
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');
//or mgr or any content you like
$modx->getService('error', 'error.modError', '', '');
$roxy = $modx->getChunk('roxyConfJson');
$file = MODX_ASSETS_PATH . 'components/tinymcewrapper/roxy/fileman/conf.json';
$fileExistingCode = file_get_contents($file);
if ($fileExistingCode) {
    if (!strpos($fileExistingCode, $roxy)) {
        $myfile = fopen($file, "w") or die("Unable to open file!");
        fwrite($myfile, $roxy);
        fclose($myfile);
    }
}
?>
<!DOCTYPE html>
<html>
<head>
<!--
  RoxyFileman - web based file manager. Ready to use with CKEditor, TinyMCE. 
  Can be easily integrated with any other WYSIWYG editor or CMS.

  Copyright (C) 2013, RoxyFileman.com - Lyubomir Arsov. All rights reserved.
  For licensing, see LICENSE.txt or http://RoxyFileman.com/license

  This program is free software: you can redistribute it and/or modify
示例#9
0
         $user->save();
         //Based on code from culd | steffan
         $uid = $user->get('id');
         $userProfile = $modx->newObject('modUserProfile');
         $userProfile->fromArray(array('internalKey' => $uid, 'fullname' => $sFirstName . ' ' . $sLastName, 'email' => $sEmail));
         $success = $user->addOne($userProfile);
         //Adds profile to created user
         if ($success) {
             $sAddLog .= $user->get('username') . ' added <br />';
             $iAddCount++;
             $sGroup == 'Administrator' ? $iRoleId = 2 : ($iRoleId = 1);
             $user->joinGroup($sGroup, $iRoleId);
             //Adds user to Group
             $user->save();
             $userProfile->save();
             $sMessage = $modx->getChunk($sEmailChunkName, array('alias' => $sAlias, 'password' => $sPass, 'sname' => $modx->getOption('site_name'), 'surl' => $modx->getOption('url_scheme') . $modx->getOption('http_host')));
             $user->sendEmail($sMessage);
         } else {
             $modx->log(modX::LOG_LEVEL_INFO, 'Failed to add ' . $sAlias . '.');
         }
     }
 }
 $user = $modx->getObject('modUser', array('username' => $sAdminUsername));
 $sMessageAdmin = $modx->getChunk($sEmailAdminChunkName, array('addCount' => $iAddCount, 'changeCount' => $iChangeCount, 'addLog' => $sAddLog, 'changeLog' => $sChangeLog));
 $modx->getService('mail', 'mail.modPHPMailer');
 $modx->mail->set(modMail::MAIL_BODY, $sMessageAdmin);
 $modx->mail->set(modMail::MAIL_FROM, $modx->config['emailsender']);
 $modx->mail->set(modMail::MAIL_FROM_NAME, $modx->config['site_name']);
 $modx->mail->set(modMail::MAIL_SENDER, $modx->config['emailsender']);
 $modx->mail->set(modMail::MAIL_SUBJECT, 'ImportUsersX import results');
 $modx->mail->setHTML(true);