Exemplo n.º 1
0
function forceproto($url)
{
    if (startswith('//', $url)) {
        $url = proto() . ':' . $url;
    }
    return $url;
}
function smarty_cms_prefilter_precompilefunc($tpl_output, &$smarty)
{
    $result = explode(':', $smarty->_current_file);
    if (count($result) > 1) {
        if (startswith($result[0], 'tmp_')) {
            $result[0] = 'template';
        }
        switch ($result[0]) {
            case 'stylesheet':
                Events::SendEvent('Core', 'StylesheetPreCompile', array('stylesheet' => &$tpl_output));
                break;
            case "content":
                Events::SendEvent('Core', 'ContentPreCompile', array('content' => &$tpl_output));
                break;
            case "template":
                Events::SendEvent('Core', 'TemplatePreCompile', array('template' => &$tpl_output));
                break;
            case "globalcontent":
                Events::SendEvent('Core', 'GlobalContentPreCompile', array('global_content' => &$tpl_output));
                break;
            default:
                break;
        }
    }
    Events::SendEvent('Core', 'SmartyPreCompile', array('content' => &$tpl_output));
    return $tpl_output;
}
Exemplo n.º 3
0
/**
 * an easy to read backtrace (uses debug_backtrace())
 * @todo longest common string should only go until / or \
 */
function callHistory()
{
    $arr = debug_backtrace();
    // find out which is the basic path each files are sharing
    // this is done to keep readability
    $base = false;
    foreach ($arr as $v) {
        if (!isset($v['file']) || !$v['file']) {
            continue;
        }
        if ($base === false) {
            $base = $v['file'];
        }
        while (!startswith($base, $v['file'])) {
            $base = substr($base, 0, -1);
        }
    }
    $ret = array(array('basepath' => $base));
    foreach ($arr as $v) {
        if (isset($v['file']) && $v['file']) {
            $ret[] = array('file' => substr($v['file'], strlen($base)), 'line' => $v['line']);
        }
    }
    return $ret;
}
Exemplo n.º 4
0
 /**
  * 
  * @param String $fieldname
  * @return String nom d'attribut réduit comme 'joueur_name' => 'name'
  */
 private function getMinName($fieldname)
 {
     if (startswith($fieldname, $this->table_name . '_')) {
         return substr($fieldname, strlen($this->table_name) + 1);
     } else {
         return $fieldname;
     }
 }
 public function test($time = '')
 {
     if (!$time) {
         $time = time();
     }
     $mod = cms_utils::get_module('FrontEndUsers');
     $lastrun = $mod->GetPreference('forcelogout_lastrun');
     $times = $mod->GetPreference('forcelogout_times');
     // like: 18:30,20:30,08:00, etc.
     if ($times == '') {
         return FALSE;
     }
     $tmp = array();
     $times = explode(',', $times);
     for ($i = 0; $i < count($times); $i++) {
         $t_h = '';
         $t_m = '';
         if (startswith($times[$i], '*')) {
             list($junk, $minutes) = explode('/', $times[$i], 2);
             $minutes = (int) $minutes;
             $minutes = max($minutes, 1);
             // minumum 2 minutes
             $minutes = min($minutes, 180);
             // maximum 180 minutes.
             for ($i = 0; $i < 60 * 24; $i += $minutes) {
                 $t_h = (int) ($i / 60);
                 $t_m = (int) ($i % 60);
                 $tmp[] = mktime((int) $t_h, (int) $t_m, 0, (int) date('m', $time), (int) date('d', $time), (int) date('Y', $time));
             }
         } else {
             list($t_h, $t_m) = explode(':', trim($times[$i]), 2);
         }
     }
     rsort($tmp);
     $fi = '';
     $ft = '';
     // find the closest entry.
     $db = cmsms()->GetDb();
     for ($i = 0; $i < count($tmp); $i++) {
         if ($time > $tmp[$i]) {
             break;
         }
         // nothing to do..
         $dt = $tmp[$i] - $time;
         if ($ft == '' || $dt < $ft - $time) {
             $fi = $i;
             $ft = $tmp[$i];
         }
     }
     if ($ft != '' && $fi != '' && $time - $ft < 60) {
         // we found something that can execute.
         $_SESSION[get_class() . '_runtime'] = $tmp[$i];
         return TRUE;
     }
     return FALSE;
 }
Exemplo n.º 6
0
function getOldParams($post)
{
    $old_params = array();
    foreach ($post as $key => $value) {
        if (startswith($key, 'old_')) {
            $old_params[] = substr($key, 4);
        }
    }
    return $old_params;
}
Exemplo n.º 7
0
function smarty_cms_prefilter_precompilefunc($tpl_output, &$smarty)
{
    global $gCms;
    $result = explode(':', $smarty->_current_file);
    if (count($result) > 1) {
        if (startswith($result[0], 'tmp_')) {
            $result[0] = 'template';
        }
        switch ($result[0]) {
            case "content":
                // 				foreach($gCms->modules as $key=>$value)
                // 				{
                // 					if ($gCms->modules[$key]['installed'] == true &&
                // 						$gCms->modules[$key]['active'] == true)
                // 					{
                // 						$gCms->modules[$key]['object']->ContentPreCompile($tpl_output);
                // 					}
                // 				}
                Events::SendEvent('Core', 'ContentPreCompile', array('content' => &$tpl_output));
                break;
            case "template":
                // 				foreach($gCms->modules as $key=>$value)
                // 				{
                // 					if ($gCms->modules[$key]['installed'] == true &&
                // 						$gCms->modules[$key]['active'] == true)
                // 					{
                // 						$gCms->modules[$key]['object']->TemplatePreCompile($tpl_output);
                // 					}
                // 				}
                Events::SendEvent('Core', 'TemplatePreCompile', array('template' => &$tpl_output));
                break;
            case "globalcontent":
                // 				foreach($gCms->modules as $key=>$value)
                // 				{
                // 					if ($gCms->modules[$key]['installed'] == true &&
                // 						$gCms->modules[$key]['active'] == true)
                // 					{
                // 						$gCms->modules[$key]['object']->GlobalContentPreCompile($tpl_output);
                // 					}
                // 				}
                Events::SendEvent('Core', 'GlobalContentPreCompile', array('global_content' => &$tpl_output));
                break;
            default:
                break;
        }
    }
    foreach ($gCms->modules as $key => $value) {
        if ($gCms->modules[$key]['installed'] == true && $gCms->modules[$key]['active'] == true) {
            $gCms->modules[$key]['object']->SmartyPreCompile($tpl_output);
        }
    }
    Events::SendEvent('Core', 'SmartyPreCompile', array('content' => &$tpl_output));
    return $tpl_output;
}
Exemplo n.º 8
0
 /**
  * Reproducing renderPage() if hell, to avoid regression.
  *
  * This highlights how bad this needs to be rewrite,
  * but let's focus on plugins for now.
  *
  * @param string $query    $_SERVER['QUERY_STRING'].
  * @param array  $get      $_SERVER['GET'].
  * @param bool   $loggedIn true if authenticated user.
  *
  * @return self::page found.
  */
 public static function findPage($query, $get, $loggedIn)
 {
     $loggedIn = $loggedIn === true ? true : false;
     if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) {
         return self::$PAGE_LINKLIST;
     }
     if (startswith($query, 'do=' . self::$PAGE_LOGIN) && $loggedIn === false) {
         return self::$PAGE_LOGIN;
     }
     if (startswith($query, 'do=' . self::$PAGE_PICWALL)) {
         return self::$PAGE_PICWALL;
     }
     if (startswith($query, 'do=' . self::$PAGE_TAGCLOUD)) {
         return self::$PAGE_TAGCLOUD;
     }
     if (startswith($query, 'do=' . self::$PAGE_OPENSEARCH)) {
         return self::$PAGE_OPENSEARCH;
     }
     if (startsWith($query, 'do=' . self::$PAGE_DAILY)) {
         return self::$PAGE_DAILY;
     }
     // At this point, only loggedin pages.
     if (!$loggedIn) {
         return self::$PAGE_LINKLIST;
     }
     if (startswith($query, 'do=' . self::$PAGE_TOOLS)) {
         return self::$PAGE_TOOLS;
     }
     if (startswith($query, 'do=' . self::$PAGE_CHANGEPASSWORD)) {
         return self::$PAGE_CHANGEPASSWORD;
     }
     if (startswith($query, 'do=' . self::$PAGE_CONFIGURE)) {
         return self::$PAGE_CONFIGURE;
     }
     if (startswith($query, 'do=' . self::$PAGE_CHANGETAG)) {
         return self::$PAGE_CHANGETAG;
     }
     if (startswith($query, 'do=' . self::$PAGE_ADDLINK)) {
         return self::$PAGE_ADDLINK;
     }
     if (isset($get['edit_link']) || isset($get['post'])) {
         return self::$PAGE_EDITLINK;
     }
     if (startswith($query, 'do=' . self::$PAGE_EXPORT)) {
         return self::$PAGE_EXPORT;
     }
     if (startswith($query, 'do=' . self::$PAGE_IMPORT)) {
         return self::$PAGE_IMPORT;
     }
     return self::$PAGE_LINKLIST;
 }
Exemplo n.º 9
0
/**
 * List all available templates.
 * @return An array {path, name, current} where path is the template path, name is the template name and current is true if this is the current template, false otherwise.
 */
function list_templates()
{
    global $config;
    $paths = array_filter(scandir(TPL_DIR), function ($item) {
        return is_dir(TPL_DIR . $item) && !startswith($item, '.');
    });
    $names = array_map('ucfirst', $paths);
    $templates = array();
    foreach ($paths as $key => $path) {
        $path .= '/';
        $templates[] = array('path' => $path, 'name' => $names[$key], 'current' => $path == $config->template);
    }
    return $templates;
}
Exemplo n.º 10
0
function check_samples($uri)
{
    if (startswith($uri, "http://example.org/")) {
        $filename = substr($uri, 19);
    } else {
        return false;
    }
    $sample_map = unserialize(sample_map);
    foreach ($sample_map as $mapkey => $mapvalue) {
        if (startswith($filename, $mapkey)) {
            return_cached($mapvalue, "samples");
        }
    }
}
Exemplo n.º 11
0
 /**
  * Create a new dataref object from a string
  * @param string $str Input string of the format __DataRef::key1val::key2val::key3val::key4val
  * @return DataRef
  */
 public static function fromString($str)
 {
     if (!startswith($str, '__DataRef::')) {
         throw new \Exception('String provided is not a valid dataref');
     }
     $parts = explode('::', $str);
     if (count($parts) < 2 || count($parts) > 5) {
         throw new \Exception('String provided is not a valid dataref');
     }
     $obj = new self();
     for ($i = 1; $i < count($parts); $i++) {
         $key = 'key' . $i;
         $obj->{$key} = $parts[$i];
     }
     return $obj;
 }
Exemplo n.º 12
0
 public static function GetCachePath($mod)
 {
     // Récupérer et traiter la préférence du dossier
     $cache_path = $mod->GetPreference("cache_path");
     // Si la préférence commence par un "/" alors l'enlever
     if (startswith($cache_path, DIRECTORY_SEPARATOR)) {
         $cache_path = substr($cache_path, 1);
     }
     // Si la préférence termine par un "/" alors l'enlever
     if (endswith($cache_path, DIRECTORY_SEPARATOR)) {
         $cache_path = substr($cache_path, -1, 1);
     }
     // Ajouter à la préférence le chemin complet
     $config = $mod->GetConfig();
     $cache_path = $config['root_path'] . DIRECTORY_SEPARATOR . "tmp" . DIRECTORY_SEPARATOR . $cache_path;
     return $cache_path;
 }
Exemplo n.º 13
0
function load_keys($list)
{
    $c = file_get_contents($list);
    $lines = explode("\n", $c);
    $result = [];
    foreach ($lines as $line) {
        $line = trim($line);
        if (substr($line, -1) == "\r") {
            $line = substr($line, 0, strlen($line) - 1);
        }
        if (startswith($line, "0.0.0.0 ")) {
            $line = substr($line, 8);
            $result[strupto($line, ' ')] = true;
        }
    }
    return $result;
}
 public static function GetTagParams($wholetag)
 {
     $matches = array();
     $result = preg_match_all(AC_BLOCK_PARAM_PATTERN, $wholetag, $matches);
     $params = array();
     for ($i = 0; $i < count($matches[1]); $i++) {
         if (startswith($matches[2][$i], '\'')) {
             $matches[2][$i] = trim($matches[2][$i], '\'');
         } else {
             if (startswith($matches[2][$i], '"')) {
                 $matches[2][$i] = trim($matches[2][$i], '"');
             }
         }
         $params[strtolower($matches[1][$i])] = $matches[2][$i];
     }
     return $params;
 }
Exemplo n.º 15
0
 function ordercontent_get_node_rec($str, $prefix = 'page_')
 {
     $gCms = cmsms();
     $tree = $gCms->GetHierarchyManager();
     if (!is_numeric($str) && startswith($str, $prefix)) {
         $str = substr($str, strlen($prefix));
     }
     $id = (int) $str;
     $tmp = $tree->find_by_tag('id', $id);
     $content = '';
     if ($tmp) {
         $content = $tmp->getContent(false, true, true);
         if ($content) {
             $rec = aray();
             $rec['id'] = (int) $str;
         }
     }
 }
Exemplo n.º 16
0
 /**
  * Convert a standard url into an SSL url
  *
  * @param string The input URL
  */
 public static function ssl_url($url)
 {
     $config = cmsms()->GetConfig();
     $ssl_url = '';
     if (isset($config['ssl_url'])) {
         $ssl_url = $config['ssl_url'];
     }
     if (empty($ssl_url)) {
         $ssl_url = str_replace('http://', 'https://', $config['root_url']);
     }
     if (startswith($url, $ssl_url)) {
         return $url;
     } else {
         if (startswith($url, $config['root_url'])) {
             $url = str_replace($config['root_url'], $ssl_url, $url);
             return $url;
         }
     }
     return FALSE;
 }
 /**
  * Gets a list of the registered bulk operations.
  *
  * @param boolean $separate_modules Split out the actions from various modules
  *                                  with a horizontal line.
  * @return array The list of operations
  */
 public static function get_operation_list($separate_modules = true)
 {
     $gCms = cmsms();
     if (!isset($gCms->variables['bulkcontent'])) {
         return FALSE;
     }
     $tmpc = array();
     $tmpm = array();
     foreach ($gCms->variables['bulkcontent'] as $name => $label) {
         if (startswith($name, 'core::')) {
             $tmpc[$name] = $label;
         } else {
             $tmpm[$name] = $label;
         }
     }
     if ($separate_modules && count($tmpm)) {
         $tmpc[-1] = '----------';
     }
     $tmpc = array_merge($tmpc, $tmpm);
     return $tmpc;
 }
Exemplo n.º 18
0
 /**
  * Set a meta variable
  *
  * {cgsm_set key=cgsm_name value='foo'}
  * {cgsm_set key=fb:admins value='bar'}
  * {cgs_set rel=fb:admins value='abc'}
  * {{cgs_set name=fb:admins 'abc'}
  */
 public static function cghm_set($params, &$template)
 {
     $vals = array();
     foreach ($params as $key => $pval) {
         switch ($key) {
             case 'name':
             case 'key':
                 $fld = self::mod()->get_raw_field($pval);
                 // check that there is only one value needed
                 if (!isset($fld['attr2'])) {
                     // get the name of the value attribute
                     $attr = $fld['attr1'];
                     $val = \cge_param::get_string($params, 'val');
                     $val = \cge_param::get_string($params, 'value', $val);
                     $val = \cge_param::get_string($params, $attr, $val);
                     $val = trim($val);
                     if ($val && $val !== '0') {
                         self::mod()->set_field_attr($pval, $attr, $val);
                     }
                 }
                 return;
             case 'rel':
                 // support multiple attributes (gotta search to make sure it is in the attrs)
                 $fld = self::mod()->get_raw_field($pval);
                 foreach ($fld as $fkey => $fval) {
                     if (!startswith($fkey, 'attr')) {
                         continue;
                     }
                     $attr = $fval;
                     $newval = \cge_param::get_string($params, $attr);
                     $newval = trim($newval);
                     if ($newval && $newval !== '0') {
                         self::mod()->set_field_attr($pval, $attr, $newval);
                     }
                 }
                 return;
         }
     }
 }
 /**
  * A utility function to test if the supplied url path is valid for the supplied content id
  *
  * @param string The partial url path to test
  * @return boolean
  */
 public static function is_valid_url($url, $content_id = '')
 {
     // check for starting or ending slashes
     if (startswith($url, '/') || endswith($url, '/')) {
         return FALSE;
     }
     // first check for invalid chars.
     $translated = munge_string_to_url($url, false, true);
     if (strtolower($translated) != strtolower($url)) {
         return FALSE;
     }
     cms_route_manager::load_routes();
     $route = cms_route_manager::find_match($url);
     if (!$route) {
         return TRUE;
     }
     if ($route->is_content()) {
         if ($content_id == '' || $route->get_content() == $content_id) {
             return TRUE;
         }
     }
     return FALSE;
 }
Exemplo n.º 20
0
 /**
  * Module API wrapper function
  *
  * @since 1.0
  * @return string
  */
 public static function WYSIWYGTextarea($name = 'textarea', $columns = '80', $rows = '15', $encoding = '', $content = '', $stylesheet = '', $addtext = '')
 {
     $mod = cms_utils::get_module('MicroTiny');
     // Check if we are in object instance
     if (!is_object($mod)) {
         return false;
     }
     // TODO: some error message?
     // Force WYSIWYG on
     $mod->wysiwygactive = true;
     // Stikki: calling this before TODO cause whole thing failing, check this Silmarillion.
     if ($stylesheet != '') {
         $_SESSION["microtiny_live_templateid"] = substr($stylesheet, strpos($stylesheet, "=") + 1);
     } else {
         $obj = cms_utils::get_app_data('editing_content');
         if (is_object($obj)) {
             $mod->templateid = $obj->TemplateId();
         } else {
             $tplops = cmsms()->GetTemplateOperations();
             $templateid = $tplops->LoadDefaultTemplate();
             $mod->templateid = $templateid->id;
         }
     }
     $origname = $name;
     if (!startswith($name, 'mt_')) {
         $name = 'mt_' . $name;
     }
     self::add_textarea($name);
     $rows = max(5, min(50, $rows));
     $output = '';
     $output .= '<textarea id="' . $name . '" name="' . $origname . '" cols="' . $columns . '" rows="' . $rows . '" ' . $addtext . '>' . cms_htmlentities($content, ENT_NOQUOTES, get_encoding($encoding)) . '</textarea>';
     global $CMS_ADMIN_PAGE;
     if ($CMS_ADMIN_PAGE && $mod->CheckPermission('MicroTiny View HTML Source')) {
         $output .= '<span style="display:block; margin-top:10px;"><input type="checkbox" id="toggle_' . $name . '" onclick="toggleMicroTiny(\'' . $name . '\');"/><label for="toggle_' . $name . '">' . $mod->Lang('view_html') . '</label></span>';
     }
     return $output;
 }
Exemplo n.º 21
0
 /**
  * A utility function to test if the supplied url path is valid for the supplied content id
  *
  * @param string The partial url path to test
  * @return boolean
  */
 public static function is_valid_url($url, $content_id = '')
 {
     // check for starting or ending slashes
     if (startswith($url, '/') || endswith($url, '/')) {
         return FALSE;
     }
     // first check for invalid chars.
     // strip off any extension (that is like 5 chars or less)
     $pos = strrpos($url, '.');
     if ($pos !== FALSE) {
         // have an extension.
         $ext = substr($url, $pos + 1);
         if (strlen($ext) >= 5 || munge_string_to_url($ext, false, true) != strtolower($ext)) {
             return FALSE;
         }
         $tmp = substr($url, 0, $pos);
         if (munge_string_to_url($tmp, false, true) != strtolower($tmp)) {
             return FALSE;
         }
     } else {
         $translated = munge_string_to_url($url, false, true);
         if (strtolower($translated) != strtolower($url)) {
             return FALSE;
         }
     }
     cms_route_manager::load_routes();
     $route = cms_route_manager::find_match($url, TRUE);
     if (!$route) {
         return TRUE;
     }
     if ($route->is_content()) {
         if ($content_id == '' || $route->get_content() == $content_id) {
             return TRUE;
         }
     }
     return FALSE;
 }
Exemplo n.º 22
0
 function get_file_listing($dir, $excludeprefix = '', $assign = '')
 {
     $gCms = cmsms();
     $smarty = $gCms->GetSmarty();
     $config = $gCms->GetConfig();
     $fileprefix = '';
     if (!empty($excludeprefix)) {
         $fileprefix = $excludeprefix;
     }
     if (startswith($dir, '/')) {
         return;
     }
     $dir = cms_join_path($config['uploads_path'], $dir);
     $list = get_matching_files($dir, '', true, true, $fileprefix, 1);
     if (!empty($assign)) {
         $smarty->assign(trim($assign), $list);
         return;
     }
     return $list;
 }
Exemplo n.º 23
0
function smarty_cms_function_dump($params, &$smarty)
{
    $ignore = array('cms', 'smarty', 'db', 'config', 'params', 'param_map', 'langhash', 'xml_exclude_files', 'xmldtd');
    if (!function_exists('build_accessor')) {
        function build_accessor($parent_str, $parent_type, $childname)
        {
            $str = $parent_str;
            if ($parent_type == 'object') {
                $str .= '-&gt;';
            } else {
                if ($parent_type == 'array') {
                    $str .= '.';
                }
            }
            $str .= $childname;
            return $str;
        }
        function dump_object($params, &$obj, $level = 1, $ignore = array(), $accessor)
        {
            $maxlevel = 3;
            if (isset($params['maxlevel'])) {
                $maxlevel = (int) $params['maxlevel'];
                $maxlevel = max(1, $maxlevel);
                $maxlevel = min(10, $maxlevel);
            }
            if ($level > $maxlevel) {
                return;
            }
            $objname = get_class($obj);
            $str = '';
            $str .= str_repeat('  ', $level) . 'Object Name: ' . $objname . '<br/>';
            $str .= str_repeat('  ', $level) . 'Parent: ' . get_parent_class($obj) . "<br/>";
            if (!isset($params['nomethods'])) {
                $methods = get_class_methods($objname);
                if (count($methods)) {
                    $str .= str_repeat('  ', $level) . 'Methods: <br/>';
                    foreach ($methods as $one) {
                        $str .= str_repeat('  ', $level) . '- ' . $one . '<br/>';
                    }
                }
            }
            if (!isset($params['novars'])) {
                $vars = get_object_vars($obj);
                if (is_array($vars) && count($vars)) {
                    $str .= str_repeat('  ', $level) . 'Properties: <br/>';
                    foreach ($vars as $name => $value) {
                        if (in_array($name, $ignore)) {
                            continue;
                        }
                        $acc = build_accessor($accessor, 'object', $name);
                        $type = gettype($value);
                        if ($type == 'object') {
                            $str .= str_repeat('  ', $level) . '- ' . '<u>' . $name . ': Object</u> <em>{$' . $acc . '}</em><br/>';
                            if (isset($params['recurse'])) {
                                $str .= dump_object($params, $value, $level + 1, $ignore, $acc);
                            }
                        } else {
                            if ($type == 'array') {
                                $str .= str_repeat('  ', $level) . '- ' . '<u>' . $name . ': Array (' . count($value) . ')</u> <em>{$' . $acc . '}</em><br/>';
                                if (isset($params['recurse'])) {
                                    $str .= dump_array($params, $value, $level + 1, $ignore, $acc);
                                }
                            } else {
                                if ($type == 'NULL') {
                                    $str .= str_repeat('  ', $level) . '- ' . $name . ': NULL <em>{$' . $acc . '}</em><br/>';
                                } else {
                                    $str .= str_repeat('  ', $level) . '- ' . $name . ' = ' . cms_htmlentities($value) . ' <em>{$' . $acc . '}</em><br/>';
                                }
                            }
                        }
                    }
                }
            }
            return $str;
        }
        function dump_array($params, &$data, $level = 1, $ignore = array(), $accessor)
        {
            $maxlevel = 3;
            if (isset($params['maxlevel'])) {
                $maxlevel = (int) $params['maxlevel'];
                $maxlevel = max(1, $maxlevel);
                $maxlevel = min(10, $maxlevel);
            }
            if ($level > $maxlevel) {
                return;
            }
            $str = '';
            foreach ($data as $key => $value) {
                $acc = build_accessor($accessor, 'array', $key);
                $type = gettype($value);
                if (is_object($value)) {
                    $str .= str_repeat('  ', $level) . '- <u>' . $key . ' = Object</u> <em>{$' . $acc . '}</em><br/>';
                    if (isset($params['recurse'])) {
                        $str .= dump_object($params, $value, $level + 1, $ignore, $acc);
                    }
                } else {
                    if (is_array($value)) {
                        $str .= str_repeat('  ', $level) . "- <u>{$key} = Array (" . count($value) . ')</u> <em>{$' . $acc . '}</em><br/>';
                        if (isset($params['recurse'])) {
                            $str .= dump_array($params, $value, $level + 1, $ignore, $acc);
                        }
                    } else {
                        if ($type == 'NULL') {
                            $str .= str_repeat('  ', $level) . '- ' . $name . ': NULL <em>{$' . $acc . '\\}</em><br/>';
                        } else {
                            $str .= str_repeat('  ', $level) . "- {$key} = " . cms_htmlentities($value) . ' {$' . $acc . '}<br/>';
                        }
                    }
                }
            }
            return $str;
        }
    }
    $gCms = cmsms();
    // get the item name (without any $)
    if (!isset($params['item'])) {
        return;
    }
    $item = trim($params['item']);
    if (startswith($item, '$')) {
        $item = substr($item, 1);
    }
    // get the base object name.
    $pos1 = strpos($item, '->');
    $pos2 = strpos($item, '-');
    $pos = $pos1;
    $len = 2;
    if ($pos2 < $pos1 && $pos2 !== FALSE) {
        $pos = $pos2;
        $len = 1;
    }
    $str = substr($item, 0, $pos);
    $work = substr($item, $pos + $len);
    // get the base object from smarty.
    $baseobj =& $smarty->get_template_vars($str);
    $obj =& $baseobj;
    $str = '$baseobj';
    $done = false;
    $tmpobj =& $baseobj->modules['Album'];
    $count = 0;
    while ($done == false) {
        $count++;
        $pos1 = strpos($work, '->');
        $pos2 = strpos($work, '.');
        if ($pos1 === FALSE) {
            $pos1 = 1000000;
        }
        if ($pos2 === FALSE) {
            $pos2 = 1000000;
        }
        $pos = $pos1;
        $len = 2;
        if ($pos2 < $pos1) {
            $pos = $pos2;
            $len = 1;
        }
        $tmp = '';
        if ($pos1 == $pos2 && $pos1 == 1000000) {
            $tmp = $work;
        } else {
            if ($pos !== FALSE && $pos < 100000) {
                $tmp = substr($work, 0, $pos);
            }
        }
        if (!empty($tmp)) {
            if (is_object($obj)) {
                $str .= '->' . $tmp;
            } else {
                if (is_array($obj)) {
                    $str .= '[\'' . $tmp . '\']';
                }
            }
            $work = substr($work, $pos + $len);
            $tmp2 = '$obj =& ' . $str . ';';
            eval($tmp2);
            $type = gettype($obj);
            if ($count > 4) {
                print_r($obj);
                echo '<hr/>';
            }
        } else {
            $done = true;
        }
    }
    $parenttype = gettype($obj);
    $str = '<pre>';
    $str .= '<strong>Dump of: $' . $item;
    $str .= '</strong> (' . ucwords($parenttype) . ')<br/>';
    if (is_object($obj)) {
        $str .= dump_object($params, $obj, 0, $ignore, $item);
    } else {
        if (is_array($obj)) {
            $str .= dump_array($params, $obj, 0, $ignore, $item);
        } else {
            $str .= $obj . '<br/>';
        }
    }
    $str .= '</pre>';
    if (isset($params['assign'])) {
        $smarty->assign(trim($params['assign']), $str);
        return;
    }
    return $str;
}
Exemplo n.º 24
0
/**
 * secondDelimiterAlfredPlaylist function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $query
 * @param mixed $settings
 * @param mixed $db
 * @param mixed $update_in_progress
 * @return void
 */
function secondDelimiterAlfredPlaylist($w, $query, $settings, $db, $update_in_progress)
{
    $words = explode('▹', $query);
    $kind = $words[0];
    $all_playlists = $settings->all_playlists;
    $is_alfred_playlist_active = $settings->is_alfred_playlist_active;
    $radio_number_tracks = $settings->radio_number_tracks;
    $now_playing_notifications = $settings->now_playing_notifications;
    $max_results = $settings->max_results;
    $alfred_playlist_uri = $settings->alfred_playlist_uri;
    $alfred_playlist_name = $settings->alfred_playlist_name;
    $country_code = $settings->country_code;
    $last_check_update_time = $settings->last_check_update_time;
    $oauth_client_id = $settings->oauth_client_id;
    $oauth_client_secret = $settings->oauth_client_secret;
    $oauth_redirect_uri = $settings->oauth_redirect_uri;
    $oauth_access_token = $settings->oauth_access_token;
    $oauth_expires = $settings->oauth_expires;
    $oauth_refresh_token = $settings->oauth_refresh_token;
    $display_name = $settings->display_name;
    $userid = $settings->userid;
    $echonest_api_key = $settings->echonest_api_key;
    $setting_kind = $words[1];
    $theplaylist = $words[2];
    if ($setting_kind == "Set Alfred Playlist") {
        $w->result(null, '', "Set your Alfred playlist", "Select one of your playlists below as your Alfred playlist", './images/settings.png', 'no', null, '');
        try {
            if (mb_strlen($theplaylist) < 3) {
                $getPlaylists = "select uri,name,nb_tracks,author,username,playlist_artwork_path,ownedbyuser,nb_playable_tracks,duration_playlist from playlists where ownedbyuser=1";
                $stmt = $db->prepare($getPlaylists);
            } else {
                $getPlaylists = "select uri,name,nb_tracks,author,username,playlist_artwork_path,ownedbyuser,nb_playable_tracks,duration_playlist from playlists where ownedbyuser=1 and ( name like :playlist or author like :playlist)";
                $stmt = $db->prepare($getPlaylists);
                $stmt->bindValue(':playlist', '%' . $theplaylist . '%');
            }
            $playlists = $stmt->execute();
        } catch (PDOException $e) {
            handleDbIssuePdoXml($db);
            return;
        }
        while ($playlist = $stmt->fetch()) {
            $added = ' ';
            if (startswith($playlist[1], 'Artist radio for')) {
                $added = '📻 ';
            }
            $w->result(null, serialize(array('', '', '', '', '', '', 'ALFRED_PLAYLIST▹' . $playlist[0] . '▹' . $playlist[1], '', '', '', '', '', '', '', '', '')), "🎵" . $added . ucfirst($playlist[1]), $playlist[7] . " tracks ● " . $playlist[8] . " ● Select the playlist to set it as your Alfred Playlist", $playlist[5], 'yes', null, '');
        }
    } elseif ($setting_kind == "Confirm Clear Alfred Playlist") {
        $w->result(null, '', "Are you sure?", "This will remove all the tracks in your current Alfred Playlist.", './images/warning.png', 'no', null, '');
        $w->result(null, '', "No, cancel", "Return to Alfred Playlist", './images/uncheck.png', 'no', null, 'Alfred Playlist▹');
        $w->result(null, serialize(array('', '', '', '', '', '', 'CLEAR_ALFRED_PLAYLIST▹' . $alfred_playlist_uri . '▹' . $alfred_playlist_name, '', '', '', '', '', '', '', '', '')), "Yes, go ahead", "This is undoable", './images/check.png', 'yes', null, '');
    }
}
Exemplo n.º 25
0
 /**
  * Get graphics for galeria from WebService, and write it on local disk.
  * @param string $filename
  * @param int $filesize
  */
 public static function PobierzPlik($gid, $filename, $orygname, $filesize)
 {
     //przygotowanie folderu
     $dir = self::GetPath();
     //wyciagnac sama nazwe pliku
     $localFileName = basename($orygname);
     $localFileName = $dir . "/" . "gal" . $gid . "/" . $localFileName;
     $pobierzPlik = false;
     //najpierw sprawdzic czy plik istnieje
     if (file_exists($localFileName)) {
         //jak plik jest to sie upewnic
         $sizeLocal = filesize($localFileName);
         if ($sizeLocal != $filesize) {
             $pobierzPlik = true;
         }
     } else {
         //brak pliku, nalezy go sciagnac
         $pobierzPlik = true;
     }
     //fizyczne pobranie pliku
     if ($pobierzPlik) {
         $handle = fopen(str_replace("sized//", "sized/", $filename) . (startswith($filename, "http") ? '?v=' . time() : ""), "r");
         if (!$handle) {
             echo "Unable to open remote file.<br />";
             exit;
         }
         $contents = '';
         while (!feof($handle)) {
             $contents .= fread($handle, 8192);
         }
         fclose($handle);
         if (!file_exists($dir . "/" . "gal" . $gid)) {
             mkdir($dir . "/" . "gal" . $gid);
             chmod($dir . "/" . "gal" . $gid, 0755);
         }
         //teraz zapis pobranego pliku na dysk
         $handle = fopen($localFileName, "w");
         fwrite($handle, $contents);
         fclose($handle);
         chmod($localFileName, 0755);
     }
 }
Exemplo n.º 26
0
$action = '';
if (isset($_POST['multiaction'])) {
    $action = $_POST['multiaction'];
}
global $gCms;
$nodelist = array();
$badlist = array();
$templateops =& $gCms->GetTemplateOperations();
if (isset($_POST['idlist'])) {
    foreach (explode(':', $_POST['idlist']) as $id) {
        $template =& $templateops->LoadTemplateByID($id);
        $nodelist[] =& $template;
    }
} else {
    foreach ($_POST as $k => $v) {
        if (startswith($k, 'multitemplate-')) {
            $id = substr($k, strlen('multitemplate-'));
            $template =& $templateops->LoadTemplateByID($id);
            if ($action == 'delete' && $template->UsageCount() > 0) {
                $badlist[] =& $template;
            } else {
                $nodelist[] =& $template;
            }
        }
    }
}
include_once "header.php";
if (count($nodelist) == 0 && count($badlist) == 0) {
    redirect("listtemplates.php" . $urlext);
} else {
    if ($action == 'delete') {
Exemplo n.º 27
0
function importFile()
{
    if (!isLoggedIn()) {
        die('Not allowed.');
    }
    $LINKSDB = new LinkDB($GLOBALS['config']['DATASTORE'], isLoggedIn(), $GLOBALS['config']['HIDE_PUBLIC_LINKS'], $GLOBALS['redirector']);
    $filename = $_FILES['filetoupload']['name'];
    $filesize = $_FILES['filetoupload']['size'];
    $data = file_get_contents($_FILES['filetoupload']['tmp_name']);
    $private = empty($_POST['private']) ? 0 : 1;
    // Should the links be imported as private?
    $overwrite = !empty($_POST['overwrite']);
    // Should the imported links overwrite existing ones?
    $import_count = 0;
    // Sniff file type:
    $type = 'unknown';
    if (startsWith($data, '<!DOCTYPE NETSCAPE-Bookmark-file-1>')) {
        $type = 'netscape';
    }
    // Netscape bookmark file (aka Firefox).
    // Then import the bookmarks.
    if ($type == 'netscape') {
        // This is a standard Netscape-style bookmark file.
        // This format is supported by all browsers (except IE, of course), also Delicious, Diigo and others.
        foreach (explode('<DT>', $data) as $html) {
            $link = array('linkdate' => '', 'title' => '', 'url' => '', 'description' => '', 'tags' => '', 'private' => 0);
            $d = explode('<DD>', $html);
            if (startswith($d[0], '<A ')) {
                $link['description'] = isset($d[1]) ? html_entity_decode(trim($d[1]), ENT_QUOTES, 'UTF-8') : '';
                // Get description (optional)
                preg_match('!<A .*?>(.*?)</A>!i', $d[0], $matches);
                $link['title'] = isset($matches[1]) ? trim($matches[1]) : '';
                // Get title
                $link['title'] = html_entity_decode($link['title'], ENT_QUOTES, 'UTF-8');
                preg_match_all('! ([A-Z_]+)=\\"(.*?)"!i', $html, $matches, PREG_SET_ORDER);
                // Get all other attributes
                $raw_add_date = 0;
                foreach ($matches as $m) {
                    $attr = $m[1];
                    $value = $m[2];
                    if ($attr == 'HREF') {
                        $link['url'] = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
                    } elseif ($attr == 'ADD_DATE') {
                        $raw_add_date = intval($value);
                        if ($raw_add_date > 30000000000) {
                            $raw_add_date /= 1000;
                        }
                        //If larger than year 2920, then was likely stored in milliseconds instead of seconds
                    } elseif ($attr == 'PRIVATE') {
                        $link['private'] = $value == '0' ? 0 : 1;
                    } elseif ($attr == 'TAGS') {
                        $link['tags'] = html_entity_decode(str_replace(',', ' ', $value), ENT_QUOTES, 'UTF-8');
                    }
                }
                if ($link['url'] != '') {
                    if ($private == 1) {
                        $link['private'] = 1;
                    }
                    $dblink = $LINKSDB->getLinkFromUrl($link['url']);
                    // See if the link is already in database.
                    if ($dblink == false) {
                        // Link not in database, let's import it...
                        if (empty($raw_add_date)) {
                            $raw_add_date = time();
                        }
                        // In case of shitty bookmark file with no ADD_DATE
                        // Make sure date/time is not already used by another link.
                        // (Some bookmark files have several different links with the same ADD_DATE)
                        // We increment date by 1 second until we find a date which is not used in DB.
                        // (so that links that have the same date/time are more or less kept grouped by date, but do not conflict.)
                        while (!empty($LINKSDB[date('Ymd_His', $raw_add_date)])) {
                            $raw_add_date++;
                        }
                        // Yes, I know it's ugly.
                        $link['linkdate'] = date('Ymd_His', $raw_add_date);
                        $LINKSDB[$link['linkdate']] = $link;
                        $import_count++;
                    } else {
                        if ($overwrite) {
                            // If overwrite is required, we import link data, except date/time.
                            $link['linkdate'] = $dblink['linkdate'];
                            $LINKSDB[$link['linkdate']] = $link;
                            $import_count++;
                        }
                    }
                }
            }
        }
        $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']);
        echo '<script>alert("File ' . json_encode($filename) . ' (' . $filesize . ' bytes) was successfully processed: ' . $import_count . ' links imported.");document.location=\'?\';</script>';
    } else {
        echo '<script>alert("File ' . json_encode($filename) . ' (' . $filesize . ' bytes) has an unknown file format. Nothing was imported.");document.location=\'?\';</script>';
    }
}
     $spamcheck_module->set_website($permalink);
     $spamcheck_module->set_body($comment->data);
     $res = $spamcheck_module->set_ham($spam_errors);
     if ($res != 'error') {
         $comment->status = CGFEEDBACK_STATUS_DRAFT;
         $comment->save();
     }
 } else {
     if (isset($params['delete_spam']) && !empty($params['delete_spam']) || isset($params['delete']) && !empty($params['delete'])) {
         $this->Redirect($id, 'admin_deletecomment', $returnid, array('cid' => $cid));
     } else {
         if (isset($params['submit']) && !empty($params['submit'])) {
             // Get values from params
             $comment->from_array($params);
             foreach ($params as $key => $value) {
                 if (startswith($key, 'field_')) {
                     $fid = (int) substr($key, 6);
                     if (is_array($value)) {
                         $value = implode(',', $value);
                     }
                     $comment->set_field_by_id($fid, $value);
                 }
             }
             // data validation
             if (empty($error) && $comment->rating < 0 || $comment->rating > 10) {
                 $error = $this->Lang('error_invalidrating');
             }
             if (empty($error) && $comment->data == '') {
                 $error = $this->Lang('error_emptycomment');
             }
             if (empty($error) && $comment->author_name == '') {
Exemplo n.º 29
0
             $pping_complexity .= "\n    " . $mapped_array[$key];
         } else {
             if ($key === "some_illos") {
                 if ($_POST["num_illos"] >= 20) {
                     $project_significant_counter++;
                 } else {
                     if ($_POST["num_illos"] > 5) {
                         $project_average_counter++;
                     }
                 }
                 $pping_complexity .= "\n    " . $_POST["num_illos"] . " Illustrations (other than minor decorations or logos)";
             } else {
                 if (startswith($key, "e1_") && !empty($value)) {
                     $level_1_errors += $value;
                 } else {
                     if (startswith($key, "e2_") && !empty($value)) {
                         $level_2_errors += $value;
                     }
                 }
             }
         }
     }
 }
 if ($project_significant_counter >= 4) {
     $pp_difficulty_level = "Difficult";
 } else {
     if ($project_significant_counter > 0 || $project_average_counter >= 3) {
         $pp_difficulty_level = "Average";
     } else {
         $pp_difficulty_level = "Easy";
     }
Exemplo n.º 30
0
 /**
  * fetch method
  * NOTE: Overwrites parent
  *
  * @param mixed $template
  * @param int $cache_id
  * @param mixed $parent
  * @param boolean $display
  * @param boolean $merge_tpl_vars
  * @param boolean $no_output_filter
  * @return mixed
  */
 public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
 {
     $name = $template;
     if (startswith($name, 'string:')) {
         $name = 'string:';
     }
     debug_buffer('', 'Fetch ' . $name . ' start');
     if (is_null($cache_id) || $cache_id === '') {
         $cache_id = $this->_global_cache_id;
     } else {
         if ($cache_id[0] == '|') {
             $cache_id = $this->_global_cache_id . $cache_id;
         }
     }
     // send an event before fetching...this allows us to change template stuff.
     if (cmsms()->is_frontend_request()) {
         $parms = array('template' => &$template, 'cache_id' => &$cache_id, 'compile_id' => &$compile_id, 'display' => &$display, 'no_output_filter' => &$no_output_filter);
         Events::SendEvent('Core', 'TemplatePreFetch', $parms);
     }
     $merge_tpl_vars = false;
     // hack
     $tmp = parent::fetch($template, $cache_id, $compile_id, $parent, $display, $merge_tpl_vars, $no_output_filter);
     debug_buffer('', 'Fetch ' . $name . ' end');
     return $tmp;
 }