예제 #1
0
 function process()
 {
     Console::initCore();
     if ($r = ArgsHolder::get()->getOption('count')) {
         $this->count = $r;
     }
     if (($c = ArgsHolder::get()->shiftCommand()) == 'help') {
         return $this->cmdHelp();
     }
     try {
         IO::out("");
         $sql = 'SELECT * FROM ' . self::TABLE . ' where not isnull(finished_at) and not 
             isnull(locked_at) and isnull(failed_at) ORDER BY run_at DESC';
         if ($this->count) {
             $list = DB::query($sql . ' LIMIT ' . $this->count);
         } else {
             $list = DB::query($sql);
         }
         if (!count($list)) {
             IO::out("No finished work!", IO::MESSAGE_FAIL);
             return;
         }
         io::out(sprintf("%-10s %-7s %-3s %-20s %-20s %-19s %-4s %-5s", "~CYAN~id", "queue", "pr", "run_at", "locked_at", "finished_at", "att", "call_to~~~"));
         foreach ($list as $l) {
             $handler = unserialize($l["handler"]);
             io::out(sprintf("%-4s %-7s %-3s %-20s %-20s %-20s %-3s %-5s", $l["id"], $l["queue"], $l["priority"], $l["run_at"], $l["locked_at"], $l["finished_at"], $l["attempts"], $handler["class"] . "::" . $handler["method"] . "(...)"));
         }
     } catch (Exception $e) {
         io::out($e->getMessage(), IO::MESSAGE_FAIL);
         return;
     }
     IO::out("");
 }
예제 #2
0
 public function RestartById($c)
 {
     if (!count(DB::query('SELECT * from ' . self::TABLE . ' WHERE id="' . $c . '"'))) {
         io::out("Work with id={$c} is not exists", IO::MESSAGE_FAIL);
         return;
     }
     $list = DB::query('SELECT * FROM ' . self::TABLE . ' where isnull(finished_at) and not 
         isnull(locked_at) and isnull(failed_at) and id=' . $c . ' ORDER BY run_at DESC');
     if (count($list)) {
         IO::out("This is working now...You cant restart!", IO::MESSAGE_FAIL);
         return;
     }
     if (IO::YES == io::dialog('Do you really want to restart work with id ' . $c . '?', IO::NO | IO::YES, IO::NO)) {
         DB::query("UPDATE " . self::TABLE . " set attempts='1',finished_at=null, locked_at=null, \n                failed_at=null, run_at=now()  WHERE  id='" . $c . "'");
         $php_path = exec("which php");
         if (empty($php_path)) {
             return $this->log("###" . date("c") . " Call from console PHP executable not found");
         }
         if (!is_executable($php_path)) {
             return $this->log("###" . date("c") . " Call from console {$php_path} could not be executed");
         }
         exec($php_path . ' ' . trim(escapeshellarg(Config::get('ROOT_DIR') . "/vendors/delayedjob/JobHandler.php"), "'") . ' >> ' . Config::get('ROOT_DIR') . '/logs/delayedjob.log 2>&1 &');
         io::done('Restarting...');
     } else {
         io::done('Cancel restart');
     }
     IO::out("");
 }
예제 #3
0
 /**
  * Output the anchor start tag
  *
  * @return string the HTML content
  * @access private
  */
 function anchorStart($tagName, $anchor, $attributes)
 {
     if (strpos($_SERVER['SCRIPT_NAME'], PATH_ADMIN_WR) !== false && strpos($_SERVER['SCRIPT_NAME'], 'page-previsualization.php') === false) {
         return '<' . $tagName . ' href="' . $anchor . '"' . $attributes . '>';
     }
     return '<' . $tagName . ' href="' . (pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_BASENAME) != 'index.php' ? $_SERVER['SCRIPT_NAME'] : pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME) . (pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME) == '/' ? '' : '/')) . (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] ? '?' . io::htmlspecialchars($_SERVER["QUERY_STRING"]) : '') . $anchor . '"' . $attributes . '>';
 }
예제 #4
0
 /**
  * Setup and configure the benchmark library class.
  */
 public function __construct()
 {
     // Run the first benchmark
     self::mark('init');
     // Register shortcut aliases using io::method();
     \io::alias(__CLASS__, get_class_methods(__CLASS__));
 }
예제 #5
0
파일: if.php 프로젝트: davidmottet/automne
    /**
     * Compute the tag
     *
     * @return string the PHP / HTML content computed
     * @access private
     */
    protected function _compute()
    {
        //decode ampersand
        $this->_attributes['what'] = io::decodeEntities($this->_attributes['what']);
        $return = '
		$ifcondition_' . $this->_uniqueID . ' = CMS_polymod_definition_parsing::replaceVars("' . $this->replaceVars($this->_attributes['what'], false, false, array($this, 'encloseWithPrepareVar')) . '", @$replace);
		';
        //if attribute name is set, store if result
        if (isset($this->_attributes['name']) && $this->_attributes['name']) {
            $return .= '$atmIfResults[\'' . $this->_attributes['name'] . '\'][\'if\'] = false;';
        }
        $return .= '
		if ($ifcondition_' . $this->_uniqueID . '):
			$func_' . $this->_uniqueID . ' = @create_function("","return (".$ifcondition_' . $this->_uniqueID . '.");");
			if ($func_' . $this->_uniqueID . ' === false) {
				CMS_grandFather::raiseError(\'Error in atm-if [' . $this->_uniqueID . '] syntax : \'.$ifcondition_' . $this->_uniqueID . ');
			}
			if ($func_' . $this->_uniqueID . ' && $func_' . $this->_uniqueID . '()):
			';
        //if attribute name is set, store if result
        if (isset($this->_attributes['name']) && $this->_attributes['name']) {
            $return .= '$atmIfResults[\'' . $this->_attributes['name'] . '\'][\'if\'] = true;';
        }
        $return .= '
				' . $this->_computeChilds() . '
			endif;
			unset($func_' . $this->_uniqueID . ');
		endif;
		unset($ifcondition_' . $this->_uniqueID . ');
		';
        return $return;
    }
예제 #6
0
 /**
  * Constructor.
  * initializes the linxCondition.
  *
  * @param string $property The page property we're gonna test. Only a set of these are available here.
  * @param string $operator The comparison operator serving to test the condition.
  * @param string $tagContent The tag content.
  * @return void
  * @access public
  */
 function __construct($tag)
 {
     $authorized_properties = array("rank", "title", "id", "lvl", "father", "website", "codename");
     $property = $tag->getAttribute('property');
     $operator = $tag->getAttribute('operator');
     if (SensitiveIO::isInSet($property, $authorized_properties)) {
         $this->_pageProperty = $property;
         $this->_operator = io::decodeEntities(io::decodeEntities(io::decodeEntities($operator)));
         $values = $tag->getElementsByTagName('value');
         if ($values->length > 0) {
             $value = $values->item(0);
             //if value type is "nodeproperty", we must parse the inner content to find a nodespec tag
             if ($value->hasAttribute("type") && $value->getAttribute("type") == "nodeproperty") {
                 $this->_valueIsScalar = false;
                 $this->_valueNodespecProperty = $value->getAttribute("property");
                 $nodespecs = $value->getElementsByTagName('nodespec');
                 if ($nodespecs->length > 0) {
                     $nodespec = $nodespecs->item(0);
                     $this->_valueNodespec = CMS_linxNodespec::createNodespec($nodespec);
                 }
             } else {
                 $this->_valueScalar = $value->nodeValue;
             }
         } else {
             $this->raiseError("Malformed innerContent");
             return;
         }
     } else {
         $this->raiseError("Unknown property : " . $property);
     }
 }
예제 #7
0
 function process()
 {
     Console::initCore();
     if (($c = ArgsHolder::get()->shiftCommand()) == 'help') {
         return $this->cmdHelp();
     }
     try {
         $format = "%-25s %s";
         IO::out("");
         $s = DB::query('SELECT * FROM ' . self::TABLE . ' where id="' . $c . '"');
         if (!count($s)) {
             io::out("Work with id={$c} is not exists", IO::MESSAGE_FAIL);
             return;
         }
         io::out(sprintf($format, "~CYAN~id~~~", $c));
         io::out(sprintf($format, "~CYAN~queue~~~", $this->emp($s[0]['queue'])));
         io::out(sprintf($format, "~CYAN~priority~~~", $this->emp($s[0]['priority'])));
         io::out(sprintf($format, "~CYAN~run at~~~", $this->emp($s[0]['run_at'])));
         io::out(sprintf($format, "~CYAN~locked at~~~", $this->emp($s[0]['locked_at'])));
         io::out(sprintf($format, "~CYAN~finished at~~~", $this->emp($s[0]['finished_at'])));
         io::out(sprintf($format, "~CYAN~failed at~~~", $this->emp($s[0]['failed_at'])));
         io::out(sprintf($format, "~CYAN~attemts~~~", $this->emp($s[0]['attempts'])));
         $handler = unserialize($s[0]["handler"]);
         io::out(sprintf($format, "~CYAN~call~~~", $handler["class"] . "::" . $handler["method"]) . "(...)");
         if (isset($handler["param"])) {
             io::out(sprintf($format, "~CYAN~params~~~", trim(self::walker($handler['param']), ',')));
         }
     } catch (Exception $e) {
         io::out($e->getMessage(), IO::MESSAGE_FAIL);
         return;
     }
     IO::out("");
 }
예제 #8
0
 /**
  * Initialize file helper class.
  *
  * @return object
  */
 public function __construct()
 {
     // By default exclude annoying files
     self::exclusive();
     // Register shortcut aliases using h::method();
     \io::alias(__CLASS__, get_class_methods(__CLASS__));
 }
 public static function create($campaignId, $data = array())
 {
     if (!io::isPositiveInteger($campaignId)) {
         return false;
     }
     $sql = 'INSERT INTO mod_mailjet VALUES (' . $campaignId . ',"' . json_encode($data) . '");';
     $query = new CMS_query($sql);
     return !$query->hasError();
 }
 public static function countByCodename($codename, $id = null)
 {
     $sql = 'SELECT count(*) as count from mod_object_oembed_definition where codename_mood = "' . io::sanitizeSQLString($codename) . '"';
     if ($id) {
         $sql .= ' AND id_mood <> ' . $id;
     }
     $query = new CMS_query($sql);
     $data = array_pop($query->getAll());
     return (int) $data['count'];
 }
예제 #11
0
 /**
  * Sets the string value.
  *
  * @param string $value the string value to set
  * @return boolean true on success, false on failure
  * @access public
  */
 function setValue($value)
 {
     //add some complementary checks on values
     if ($value && io::strlen($value) > 255) {
         $this->raiseError("Setting a too long string for string value : max 255 cars, set : " . io::strlen($value));
         return false;
     }
     $this->_value = $value;
     return true;
 }
예제 #12
0
파일: CmdEnv.php 프로젝트: point/cassea
 function CmdList()
 {
     io::out('~WHITE~Current env~~~: ' . ($env = EnvManager::getCurrent()));
     io::out();
     IO::OUt('~WHITE~Avaible enviroments:~~~');
     foreach (EnvManager::envList() as $e) {
         if ($e != $env) {
             io::out('    ' . $e);
         }
     }
 }
예제 #13
0
 /**
  * Gets all available objects class names
  *
  * @return array(string "CMS_object_{type}")
  * @access public
  * @static
  */
 function getObjectsNames()
 {
     //Automatic listing
     $excludedFiles = array('object_catalog.php', 'object_common.php');
     $packages_dir = dir(PATH_MODULES_FS . '/' . MOD_POLYMOD_CODENAME . '/objects/');
     while (false !== ($file = $packages_dir->read())) {
         if (io::substr($file, -4) == ".php" && !in_array($file, $excludedFiles) && class_exists('CMS_' . io::substr($file, 0, -4))) {
             $objectsCatalog[] = 'CMS_' . io::substr($file, 0, -4);
         }
     }
     return $objectsCatalog;
 }
예제 #14
0
 public function deleteQueue($c)
 {
     if (!DB::query('SELECT id from ' . self::TABLE . ' WHERE queue="' . $c . '"')) {
         io::out("Queue {$c} is not exists", IO::MESSAGE_FAIL);
         return;
     }
     if (IO::YES == io::dialog('Realy you really want to delete all jobs with queue ' . $c . '?', IO::NO | IO::YES, IO::NO)) {
         DB::query("DELETE FROM " . self::TABLE . " WHERE  queue='" . $c . "'");
         io::done('Deleting...');
     } else {
         io::done('Cancel delete');
     }
 }
예제 #15
0
 /**
  * Get the text definition.
  *
  * @return string The text definition based on the current elements
  * @access public
  */
 function getTextDefinition()
 {
     $text = '';
     foreach ($this->_elements as $atom) {
         $text .= $atom[0];
         if ($this->_valuesByAtom == 2) {
             $text .= "," . $atom[1];
         }
         $text .= ";";
     }
     $text = io::substr($text, 0, -1);
     return $text;
 }
예제 #16
0
 /**
  * Initialize the agent class.
  *
  * @return
  */
 public function __construct()
 {
     // Initialize
     self::timeout();
     self::secure();
     // Configure user agent (name)
     $this->data['agent']['name'] = \io::helper('web')->proper();
     // Configure user agent (site or domain)
     $this->data['agent']['site'] = \io::helper('web')->site();
     // Prepares parameters for new CURL request
     $this->resetter('pre', 'post', 'status');
     // Maximum number of redirects
     $this->data['max_redirects'] = 10;
 }
예제 #17
0
 /**
  * Constructor
  * 
  * @param string $filename, the filename to use. io::sanitizeAsciiString will be used to clean this filename
  * @param string $filepath, the filepath to use (FS relativeà). The path must exists and be writable. Default : PATH_TMP_FS
  * @param string $separator, the CSV fields separator (default ;)
  * @param string $enclosure, the CSV fields enclosure (default ")
  * @return void
  */
 function __construct($filename, $filepath = PATH_TMP_FS, $separator = ';', $enclosure = '"')
 {
     if (is_dir($filepath) && is_writable($filepath)) {
         $this->_filepath = $filepath;
     } else {
         $this->raiseError('File path does not exists or is not writable : ' . $filepath);
         return false;
     }
     $this->_filename = io::sanitizeAsciiString($filename);
     $this->_separator = $separator;
     $this->_enclosure = $enclosure;
     if (!($this->_file = @fopen($this->_filepath . '/' . $this->_filename, 'ab+'))) {
         $this->raiseError('Cannot open file ' . ($this->_filepath . '/' . $this->_filename) . ' for writing');
         return false;
     }
 }
예제 #18
0
 /**
  * Constructor.
  * Initializes the process manager and lauches the action if all went well, then delete the PIDFile
  * NOTE : SCRIPT_CODENAME is a constant that must be defined, and unique accross all usage of the background scripts
  * (i.e. One background script for one application should have the same, but two applications having the same script shouldn't collate)
  *
  * @param boolean $debug Set to true if you want a debug of what the script does
  * @return void
  * @access public
  */
 function backgroundScript($debug = false, $scriptID = 'Master')
 {
     $this->_debug = $debug;
     $this->_processManager = new processManager(SCRIPT_CODENAME . '_' . $scriptID);
     // Cleans previous PIDs
     if (isset($_SERVER['argv']['3']) && $_SERVER['argv']['3'] == '-F') {
         if (!APPLICATION_IS_WINDOWS) {
             $tmpDir = dir($this->_processManager->getTempPath());
             while (false !== ($file = $tmpDir->read())) {
                 if (io::strpos($file, SCRIPT_CODENAME) !== false) {
                     @unlink($this->_processManager->getTempPath() . '/' . $file);
                 }
             }
         } else {
             $files = glob(realpath($this->_processManager->getTempPath()) . '/' . SCRIPT_CODENAME . '*.*', GLOB_NOSORT);
             if (is_array($files)) {
                 foreach ($files as $file) {
                     if (!CMS_file::deleteFile($file)) {
                         $this->raiseError("Can't delete file " . $file);
                     }
                 }
             }
         }
     }
     //write script process PID File
     if ($this->_processManager->writePIDFile()) {
         if ($this->_debug) {
             $this->raiseError("PID file successfully written (" . $this->_processManager->getPIDFileName() . ").");
         }
         //start script process
         $this->activate($this->_debug);
         //delete script process PID File
         if ($this->_processManager->deletePIDFile()) {
             if ($this->_debug) {
                 $this->raiseError("PID file successfully deleted (" . $this->_processManager->getPIDFileName() . ").");
             }
         } else {
             $this->raiseError("Can not delete PID file (" . $this->_processManager->getPIDFileName() . ").");
         }
         exit;
     } else {
         if ($this->_debug) {
             $this->raiseError("PID file already exists or impossible to write (" . $this->_processManager->getPIDFileName() . ").");
         }
         exit;
     }
 }
예제 #19
0
 /**
  * Initialize cron helper class.
  *
  * @return object
  */
 public function __construct()
 {
     // Initialize defaults
     self::$data['jobs'] = array();
     self::$data['crontab'] = '/usr/bin/crontab';
     // Reads the crontab file into a string
     $crontab = stream_get_contents(popen(self::$data['crontab'] . ' -l', 'r'));
     // Iterates through all non-empty lines from crontab file
     foreach (array_filter(explode(PHP_EOL, $crontab)) as $line) {
         // Ignore comment lines
         if (trim($line)[0] != '#') {
             // Parse jobs into a developer friendly format
             self::$data['jobs'][md5($line)] = self::parse($line);
         }
     }
     // Register shortcut aliases using h::method();
     \io::alias(__CLASS__, ['tasks', 'flush', 'schedule', 'unschedule']);
 }
예제 #20
0
파일: CmdSwitch.php 프로젝트: point/cassea
 function process()
 {
     if (!($c = ArgsHolder::get()->shiftCommand())) {
         return io::out('Incorrect parameter', IO::MESSAGE_FAIL) | 1;
     }
     $root = Config::get('ROOT_DIR');
     $file = $root . '/includes/env/' . strtolower($c) . '_env.php';
     if (!file_exists($file)) {
         return io::out('Mode ' . $c . ' not exists', IO::MESSAGE_FAIL) | 1;
     }
     IO::out('Updating Loader', false);
     $loader = fopen($root . '/includes/env/Loader.php', 'w');
     flock($loader, LOCK_EX);
     $put = '<?php require_once("' . $c . '_env.php");';
     fwrite($loader, $put);
     flock($loader, LOCK_UN);
     fclose($loader);
     io::done();
     io::out('Backup config.ini', false);
     if (copy($root . '/config/config.ini', $root . '/config/config.ini.bak')) {
         io::done();
     } else {
         return IO::out('Can\'t backup file config.ini', IO::MESSAGE_FAIL) | 1;
     }
     IO::out('Updating config.ini', false);
     $file_array = file($root . '/config/config.ini');
     $str = null;
     foreach ($file_array as $fa) {
         if (preg_match('/\\[\\s*config\\s*:\\s*\\S+\\]/', $fa, $match)) {
             $str .= '[config : ' . $c . ']' . PHP_EOL;
         } else {
             $str .= $fa;
         }
     }
     $config = fopen($root . '/config/config.ini', 'w');
     flock($config, LOCK_EX);
     fwrite($config, $str);
     flock($config, LOCK_UN);
     fclose($config);
     io::done();
     IO::done('Enviroments set to ~WHITE~' . $c . '~~~');
 }
예제 #21
0
 static function transform1($params)
 {
     $url = $params['image'];
     $data = $params['data'];
     $info = image::image_info($url);
     $path = $info['path'];
     if (!io::file_exists($path)) {
         throw new \Exception(resources::message('FILE_NOT_EXISTS', $path));
     }
     if (meta::exists($info['id'])) {
         $meta = meta::get($info['id']);
         $spath = util::apath($meta['orig']);
         $data = isset($meta['data']) ? image::combine_transform($meta['data'], $data) : $data;
     } else {
         $spath = $path;
     }
     $id = util::id();
     $name = $id . '.' . $info['ext'];
     $dpath = DRAFT_CONTENT_DIR . '/' . $name;
     image::transform_image($spath, $dpath, $data);
     meta::put($id, array('orig' => util::rpath($spath), 'oid' => $info['id'], 'path' => util::rpath($dpath), 'name' => $name, 'data' => $data, 'image' => true));
     return array('status' => 0, 'url' => DRAFT_CONTENT_URL . '/' . $name);
 }
예제 #22
0
파일: CmdGroup.php 프로젝트: point/cassea
 public function cmdUserlist()
 {
     if (!count(ACL::getGroups())) {
         return io::out('There is no groups yet.');
     }
     $users = ACL::getUsers();
     if ($group = ArgsHolder::get()->shiftCommand()) {
         if (!in_array($group, array_values(ACL::getGroups()))) {
             return io::out("No such group {$group}", IO::MESSAGE_FAIL) | 3;
         }
         IO::out("~WHITE~User(s) from group " . $group . "~~~:");
         foreach ($users[$group] as $u) {
             IO::out(" " . $u);
         }
     } else {
         foreach (array_keys($users) as $g) {
             IO::out("~WHITE~Group " . $g . "~~~:");
             foreach ($users[$g] as $u) {
                 IO::out(" " . $u);
             }
         }
     }
 }
예제 #23
0
파일: CmdClone.php 프로젝트: point/cassea
 function process()
 {
     $root = Config::get('ROOT_DIR');
     if (($src = ArgsHolder::get()->shiftCommand()) === false || ($new = ArgsHolder::get()->shiftCommand()) === false) {
         return io::out('Incorrect param count', IO::MESSAGE_FAIL) | 1;
     }
     $src_file = $root . '/includes/env/' . strtolower($src) . '_env.php';
     $new_file = $root . '/includes/env/' . strtolower($new) . '_env.php';
     if (file_exists($new_file)) {
         return io::out('Enviroments ~WHITE~' . $new . '~~~ already exists!', IO::MESSAGE_FAIL) | 2;
     }
     if (!file_exists($src_file)) {
         return io::out('Source enviroments ~WHITE~' . $src . '~~~ is not exists!', IO::MESSAGE_FAIL) | 2;
     }
     io::out('Writing files', false);
     if (!copy($src_file, $new_file)) {
         return io::out('Unable copy env files (' . $src_file . ' to ' . $new_file . ')', IO::MESSAGE_FAIL) | 3;
     }
     $file_array = file($root . '/config/config.ini');
     $str = null;
     foreach ($file_array as $fa) {
         if (preg_match('/\\[\\s*config\\s*:\\s*\\S+\\]/', $fa, $match)) {
             $str .= '[' . $new . ': base ]' . PHP_EOL . $match[0] . PHP_EOL;
         } else {
             $str .= $fa;
         }
     }
     $config = fopen($root . '/config/config.ini', 'w');
     flock($config, LOCK_EX);
     $r = fwrite($config, $str);
     flock($config, LOCK_UN);
     fclose($config);
     if (!$r) {
         return io::out('Cant write ~WHITE~config.ini~~~', IO::MESSAGE_FAIL) | 4;
     }
     io::done();
 }
예제 #24
0
function formatBytes($val, $digits = 3, $mode = "SI", $bB = "B")
{
    $si = array("", "K", "M", "G", "T", "P", "E", "Z", "Y");
    $iec = array("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi");
    switch (io::strtoupper($mode)) {
        case "SI":
            $factor = 1000;
            $symbols = $si;
            break;
        case "IEC":
            $factor = 1024;
            $symbols = $iec;
            break;
        default:
            $factor = 1000;
            $symbols = $si;
            break;
    }
    switch ($bB) {
        case "b":
            $val *= 8;
            break;
        default:
            $bB = "B";
            break;
    }
    for ($i = 0; $i < count($symbols) - 1 && $val >= $factor; $i++) {
        $val /= $factor;
    }
    $p = io::strpos($val, ".");
    if ($p !== false && $p > $digits) {
        $val = round($val);
    } elseif ($p !== false) {
        $val = round($val, $digits - $p);
    }
    return round($val, $digits) . " " . $symbols[$i] . $bB;
}
예제 #25
0
파일: CmdPhpInfo.php 프로젝트: point/cassea
 private function infoByExt($ext)
 {
     $info = $this->extInfo();
     if (isset($info[$ext])) {
         $extinfo = $info[$ext];
         io::out('');
         io::out('~WHITE~Information about extension ' . $ext . ":~~~");
         foreach ($extinfo as $ei) {
             foreach ($ei as $k => $v) {
                 if (is_array($v)) {
                     array_pop($v);
                     foreach ($v as $kk => $vv) {
                         io::out(sprintf("%-40s %s", $k, "~CYAN~" . $vv . "~~~"));
                     }
                 } else {
                     io::out(sprintf("%-40s %s", $k, "~CYAN~" . $v . "~~~"));
                 }
             }
         }
         io::out('');
     } else {
         io::out('No such extension  ' . $ext, IO::MESSAGE_FAIL);
     }
 }
예제 #26
0
    /**
     * Get the HTML form given the block HTML example data.
     *
     * @param CMS_language &$language The language of the administration frontend
     * @param CMS_page &$page The page which contains the client space
     * @param CMS_clientSpace &$clientSpace The client space which contains the row
     * @param CMS_row &$row The row which contains the block
     * @param integer $blockID The tag ID of the block
     * @param string $data The data to show as example
     * @return string The HTML form which can send to the page that will modify the block
     * @access private
     */
    protected function _getHTMLForm($language, &$page, &$clientSpace, &$row, $blockID, $data)
    {
        global $cms_user;
        //append atm-block class and block-id to all first level tags found in block datas
        $domdocument = new CMS_DOMDocument();
        try {
            $domdocument->loadXML('<block>' . $data . '</block>');
        } catch (DOMException $e) {
            $this->raiseError('Parse error for ' . get_class($this) . ' : Page ' . $page->getID() . ' - Row "' . $row->getTagID() . '" - Block "' . $blockID . '" : ' . $e->getMessage());
            $data = '<div class="atm-error-block atm-block-helper">' . $language->getMessage(self::MESSAGE_BLOCK_CONTENT_ERROR) . '</div>';
            $domdocument = new CMS_DOMDocument();
            $domdocument->loadXML('<block>' . $data . '</block>');
        }
        $blockNodes = $domdocument->getElementsByTagName('block');
        if ($blockNodes->length == 1) {
            $blockXML = $blockNodes->item(0);
        }
        //check for valid tags nodes inside current block tag
        $hasNode = false;
        foreach ($blockXML->childNodes as $blockChildNode) {
            //scripts tags and p tags are not correctly handled by javascript
            if (is_a($blockChildNode, 'DOMElement') && $blockChildNode->tagName != 'script') {
                $hasNode = true;
            }
        }
        foreach ($blockXML->childNodes as $blockChildNode) {
            //scripts tags and p tags are not correctly handled by javascript
            if (is_a($blockChildNode, 'DOMElement') && ($blockChildNode->tagName != 'p' || io::substr($blockChildNode->tagName, 0, 4) != 'atm-')) {
                $hasNode = false;
            }
        }
        if (!$hasNode) {
            //append div with atm-empty-block class around datas
            $domdocument = new CMS_DOMDocument();
            try {
                $domdocument->loadXML('<block><div class="atm-empty-block atm-block-helper">' . $data . '</div></block>');
            } catch (DOMException $e) {
                $this->raiseError('Parse error for block : ' . $e->getMessage() . " :\n" . $data, true);
                return '';
            }
            $blockNodes = $domdocument->getElementsByTagName('block');
            if ($blockNodes->length == 1) {
                $blockXML = $blockNodes->item(0);
            }
        }
        $elements = array();
        $uniqueId = 'block-' . md5(mt_rand() . microtime());
        foreach ($blockXML->childNodes as $blockChildNode) {
            if (is_a($blockChildNode, 'DOMElement') && $blockChildNode->tagName != 'script' && $blockChildNode->tagName != 'p' && io::substr($blockChildNode->tagName, 0, 4) != 'atm-') {
                if ($blockChildNode->hasAttribute('class')) {
                    $blockChildNode->setAttribute('class', $blockChildNode->getAttribute('class') . ' atm-block ' . $uniqueId);
                } else {
                    $blockChildNode->setAttribute('class', 'atm-block ' . $uniqueId);
                }
                $elementId = 'el-' . md5(mt_rand() . microtime());
                $blockChildNode->setAttribute('id', $elementId);
                $elements[] = $elementId;
            }
        }
        $data = CMS_DOMDocument::DOMElementToString($blockXML, true);
        //add block JS specification
        $data = '
		<script type="text/javascript">
			atmBlocksDatas[\'' . $uniqueId . '\'] = {
				page:				\'' . $page->getID() . '\',
				document:			document,
				clientSpaceTagID:	\'' . $clientSpace->getTagID() . '\',
				row:				\'' . $row->getTagID() . '\',
				id:					\'' . $blockID . '\',
				jsBlockClass:		\'' . $this->_jsBlockClass . '\',
				hasContent:			\'' . $this->_hasContent . '\',
				editable:			\'' . $this->_editable . '\',
				administrable:		\'' . $this->_administrable . '\',
				options:			' . io::jsonEncode($this->_options) . ',
				value:				' . (is_array($this->_value) ? sensitiveIO::jsonEncode($this->_value) : '\'' . sensitiveIO::sanitizeJSString($this->_value) . '\'') . ',
				elements:			[' . ($elements ? '\'' . implode('\',\'', $elements) . '\'' : '') . ']
			};
		</script>
		' . $data;
        return $data;
    }
예제 #27
0
 /**
  * get an object value
  *
  * @param string $name : the name of the value to get
  * @param string $parameters (optional) : parameters for the value to get
  * @return multidimentionnal array : the object values structure
  * @access public
  */
 function getValue($name, $parameters = '')
 {
     if (in_array($name, array('fieldname', 'required', 'fieldID', 'value'))) {
         return parent::getValue($name, $parameters);
     }
     $params = $this->getParamsValues();
     if ($name == 'hasValue') {
         return $this->_subfieldValues[0]->getValue() ? true : false;
     }
     //oembed values : first, get size parameters
     @(list($width, $height) = explode(',', str_replace(';', ',', $parameters)));
     if (!io::isPositiveInteger($width)) {
         $width = '';
     }
     if (!io::isPositiveInteger($height)) {
         $height = '';
     }
     //load oembed object
     if (in_array($name, array('html', 'width', 'height'))) {
         //size specific values : get oembed object at queried size
         if (!isset($this->_oembedObjects[$width . '-' . $height])) {
             $this->_oembedObjects[$width . '-' . $height] = new CMS_oembed($this->_subfieldValues[0]->getValue(), $width, $height, $params['embedlyKey']);
         }
         $oembed = $this->_oembedObjects[$width . '-' . $height];
     } else {
         if ($this->_oembedObjects) {
             //load current oembed object
             $oembed = current($this->_oembedObjects);
         } else {
             $this->_oembedObjects[$width . '-' . $height] = new CMS_oembed($this->_subfieldValues[0]->getValue(), $width, $height, $params['embedlyKey']);
             $oembed = $this->_oembedObjects[$width . '-' . $height];
         }
     }
     if (!$oembed->hasProvider()) {
         return '';
     }
     if ($name == 'authorName') {
         $name = 'author_name';
     }
     if ($name == 'authorUrl') {
         $name = 'author_url';
     }
     if ($name == 'authorName') {
         $name = 'author_name';
     }
     if ($name == 'providerUrl') {
         $name = 'provider_url';
     }
     switch ($name) {
         case 'html':
             return $oembed->getHTML(array('class' => 'atm-embed'));
             break;
         case 'thumb':
             return $oembed->getThumbnail(array('class' => 'atm-thumb-embed'));
             break;
         case 'providerName':
             return io::htmlspecialchars($oembed->getProviderName());
             break;
         case 'url':
             return $this->_subfieldValues[0]->getValue();
             break;
         case 'datas':
             return $oembed->getDatas();
             break;
         default:
             return io::htmlspecialchars($oembed->getData($name));
             break;
     }
 }
예제 #28
0
 /**
  * Extract files from the archive
  * 
  * @return true on success
  */
 function extract_files()
 {
     $pwd = getcwd();
     chdir($this->options['basedir']);
     if ($fp = $this->open_archive()) {
         if ($this->options['inmemory'] == 1) {
             $this->files = array();
         }
         while ($block = fread($fp, 512)) {
             $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100temp/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block);
             $file = array('name' => $temp['prefix'] . $temp['name'], 'stat' => array(2 => $temp['mode'], 4 => octdec($temp['uid']), 5 => octdec($temp['gid']), 7 => octdec($temp['size']), 9 => octdec($temp['mtime'])), 'checksum' => octdec($temp['checksum']), 'type' => $temp['type'], 'magic' => $temp['magic']);
             if ($file['checksum'] == 0x0) {
                 break;
             } else {
                 /*if ($file['magic'] != "ustar") {
                 			$this->raiseError("This script does not support extracting this type of tar file.");
                 			break;
                 		}*/
                 $block = substr_replace($block, "        ", 148, 8);
             }
             $checksum = 0;
             for ($i = 0; $i < 512; $i++) {
                 $checksum += ord(io::substr($block, $i, 1));
             }
             if ($file['checksum'] != $checksum) {
                 $this->raiseError("Could not extract from {$this->options['name']}, it is corrupt.");
             }
             if ($this->options['inmemory'] == 1) {
                 $file['data'] = @fread($fp, $file['stat'][7]);
                 @fread($fp, 512 - $file['stat'][7] % 512 == 512 ? 0 : 512 - $file['stat'][7] % 512);
                 unset($file['checksum'], $file['magic']);
                 $this->files[] = $file;
             } else {
                 if ($file['type'] == 5) {
                     if (!is_dir($file['name'])) {
                         /*if ($this->options['forceWriting']) {
                         			chmod($file['name'], 1777);
                         		}*/
                         if (!$this->options['dontUseFilePerms']) {
                             @mkdir($file['name'], $file['stat'][2]);
                             //pr($file['name'].' : '.$file['stat'][4]);
                             //pr($file['name'].' : '.$file['stat'][5]);
                             @chown($file['name'], $file['stat'][4]);
                             @chgrp($file['name'], $file['stat'][5]);
                         } else {
                             @mkdir($file['name']);
                         }
                     }
                 } else {
                     if ($this->options['overwrite'] == 0 && file_exists($file['name'])) {
                         $this->raiseError("{$file['name']} already exists.");
                     } else {
                         //check if destination dir exists
                         $dirname = dirname($file['name']);
                         if (!is_dir($dirname)) {
                             CMS_file::makeDir($dirname);
                         }
                         if ($new = @fopen($file['name'], "wb")) {
                             @fwrite($new, @fread($fp, $file['stat'][7]));
                             @fread($fp, 512 - $file['stat'][7] % 512 == 512 ? 0 : 512 - $file['stat'][7] % 512);
                             @fclose($new);
                             //pr($file['name'].' : '.$file['stat'][2]);
                             if (!$this->options['dontUseFilePerms']) {
                                 @chmod($file['name'], $file['stat'][2]);
                                 @chown($file['name'], $file['stat'][4]);
                                 @chgrp($file['name'], $file['stat'][5]);
                             }
                             /*if ($this->options['forceWriting']) {
                             			chmod($file['name'], 0777);
                             		}*/
                         } else {
                             $this->raiseError("Could not open {$file['name']} for writing.");
                         }
                     }
                 }
             }
             unset($file);
         }
     } else {
         $this->raiseError("Could not open file {$this->options['name']}");
     }
     chdir($pwd);
     return true;
 }
 /** 
  * Get the default language code for this module
  * Comes from parameters or Constant
  * Upgrades constant with parameter found
  *
  * @return String the language codename
  * @access public
  */
 function getDefaultLanguageCodename()
 {
     if (!defined("MOD_" . io::strtoupper($this->getCodename()) . "_DEFAULT_LANGUAGE")) {
         $polymodLanguages = CMS_object_i18nm::getAvailableLanguages();
         define("MOD_" . io::strtoupper($this->getCodename()) . "_DEFAULT_LANGUAGE", $polymodLanguages[0]);
     }
     return constant("MOD_" . io::strtoupper($this->getCodename()) . "_DEFAULT_LANGUAGE");
 }
예제 #30
0
 /**
  * get an object value
  *
  * @param string $name : the name of the value to get
  * @param string $parameters (optional) : parameters for the value to get
  * @return multidimentionnal array : the object values structure
  * @access public
  */
 function getValue($name, $parameters = '')
 {
     $href = new CMS_href($this->_subfieldValues[0]->getValue());
     switch ($name) {
         case 'validhref':
             return $href->hasValidHREF();
             break;
         case 'hrefvalue':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->_public ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             return $href->getHTML(false, $moduleCodename, $location, false, true);
             break;
         case 'hreflabel':
             return io::htmlspecialchars($href->getLabel());
             break;
         case 'hreftarget':
             return $href->getTarget();
             break;
         case 'hreftype':
             return $href->getLinkType();
             break;
         case 'popupWidth':
             $popup = $href->getPopup();
             return $popup['width'];
             break;
         case 'popupHeight':
             $popup = $href->getPopup();
             return $popup['height'];
             break;
         case 'hrefHTML':
             //get module codename
             $moduleCodename = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //set location
             $location = $this->_public ? RESOURCE_DATA_LOCATION_PUBLIC : RESOURCE_DATA_LOCATION_EDITED;
             //add link title (if any)
             if ($parameters) {
                 $title = $parameters;
                 //add title attribute to link
                 $href->setAttributes(array('title' => io::htmlspecialchars($href->getLabel() . ' (' . $title . ')')));
             } else {
                 $title = false;
                 //add title attribute to link
                 $href->setAttributes(array('title' => io::htmlspecialchars($href->getLabel())));
             }
             return $href->getHTML($title, $moduleCodename, $location);
             break;
         default:
             return parent::getValue($name, $parameters);
             break;
     }
 }