Overview

Packages

  • None
  • PHPShopArray
  • PHPShopClass
    • Helper
  • PHPShopCore
  • PHPShopElements
  • PHPShopGUI
  • PHPShopInc
  • PHPShopObj
  • PHPShopParser
  • PHPShopTest

Classes

  • fase4_rdf
  • PHPShopAdminRule
  • PHPShopArray
  • PHPShopBannerElement
  • PHPShopBase
  • PHPShopBaseXml
  • PHPShopCatalogElement
  • PHPShopCategory
  • PHPShopCategoryArray
  • PHPShopCloudElement
  • PHPShopCore
  • PHPShopCoretest
  • PHPShopCssParser
  • PHPShopDate
  • PHPShopDebug
  • PHPShopDoc
  • PHPShopElements
  • PHPShopFile
  • PHPShopForma
  • PHPShopFrontInterface
  • PHPShopGbook
  • PHPShopGbookElement
  • PHPShopGUI
  • PHPShopIndex
  • PHPShopInterface
  • PHPShopLang
  • PHPShopLinks
  • PHPShopMail
  • PHPShopMailFile
  • PHPShopMap
  • PHPShopModules
  • PHPShopNav
  • PHPShopNews
  • PHPShopNewsElement
  • PHPShopObj
  • PHPShopOpros
  • PHPShopOprosElement
  • PHPShopOrm
  • PHPShopPage
  • PHPShopPageCategory
  • PHPShopPageCategoryArray
  • PHPShopPages
  • PHPShopParser
  • PHPShopPhoto
  • PHPShopPhotoCategory
  • PHPShopPhotoCategoryArray
  • PHPShopPhotoElement
  • PHPShopReadCsv
  • PHPShopReadCsvNative
  • PHPShopReadCsvPro
  • PHPShopRestore
  • PHPShopRssParser
  • PHPShopSearch
  • PHPShopSecurity
  • PHPShopSkinElement
  • PHPShopSkinmarket
  • PHPShopSliderElement
  • PHPShopString
  • PHPShopSystem
  • PHPShopText
  • PHPShopTextElement
  • PHPShopUpdate
  • XMLparser

Functions

  • __
  • allowedFunctions
  • array2iconv
  • CheckCanGzip
  • debug
  • evalstr
  • GzDocOut
  • Open
  • output_handler
  • parseDatabase
  • Parser
  • ParseTemplate
  • ParseTemplateReturn
  • PHPShopAutoLoadClass
  • phpshopparserevalstr
  • preExtractCallBack
  • readDatabase
  • stripslashes_deep
  • SysValueReturn
  • timer
  • tmpGetFile
  • utf8_win1251
  • writeLangFile
  • xml2array
  • Overview
  • Package
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 
<?php

/**

 * @author PHPShop Software
 * @version 1.14
 * @package PHPShopClass
 * @tutorial http://doc.phpshop.ru/PHPShopClass/PHPShopModules.html
 */
class PHPShopModules {

    /**

     */
    var $ModValue = array();

    /**

     */
    var $ModDir;

    /**

     */
    var $debug = false;

    /**

     */
    var $memory = false;
    var $unload = array();

    /**


     */
    function __construct($ModDir = "phpshop/modules/", $mod_path = false) {
        $this->ModDir = $ModDir;
        $this->objBase = $GLOBALS['SysValue']['base']['modules'];

        $this->PHPShopOrm = new PHPShopOrm($this->objBase);
        $this->PHPShopOrm->debug = $this->debug;

        $this->path = $mod_path;

        $this->checkKeyBase();

        //
        $this->addTemplateHook();

        $data = $this->PHPShopOrm->select(array('*'), false, false, array('limit' => 100));
        if (is_array($data))
            foreach ($data as $row) {
                $path = $row['path'];
                if (empty($_SESSION[$this->getKeyName()][crc32($path)]) or $this->path)
                    $this->getIni($path);
            }


        //
        foreach ($this->unload as $v)
            $this->getIni($v, false);
    }

    /**

     */
    function addTemplateHook() {
        $ini = 'phpshop/templates' . chr(47) . @$_SESSION['skin'] . "/php/inc/config.ini";
        if (file_exists($ini)) {
            $SysValue = @parse_ini_file($ini, 1);

            if (is_array($SysValue['autoload']))
                foreach ($SysValue['autoload'] as $k => $v)
                    if (!strstr($k, '#'))
                        $this->ModValue['autoload'][$k] = './phpshop/templates/' . $_SESSION['skin'] . chr(47) . $v;

            if (is_array($SysValue['unload']))
                foreach ($SysValue['unload'] as $k => $v)
                    if (!strstr($k, '#')) {
                        if (strstr($v, ','))
                            $unload_array = explode(",", $v);
                        else
                            $unload_array[] = $v;
                        foreach ($unload_array as $kill)
                            $this->unload[] = $kill;
                    }

            if (is_array($SysValue['hook']))
                foreach ($SysValue['hook'] as $k => $v)
                    if (!strstr($k, '#'))
                        $this->ModValue['hook'][$k][] = './phpshop/templates/' . $_SESSION['skin'] . chr(47) . $v;

            //
            if (is_array($SysValue['html'])) {
                foreach ($SysValue['html'] as $k => $v)
                    if (!strstr($k, '#'))
                        $GLOBALS['SysValue']['html'][$k] = $v;
            }
            else
                unset($GLOBALS['SysValue']['html']);
        }
    }

    /**


     */
    function getUpdate($version = false) {
        global $link_db;

        if (empty($version))
            $version = 'default';

        $file = '../modules/' . $this->path . '/updates/' . $version . '/update_module.sql';

        if (file_exists($file)) {
            $sql = file_get_contents($file);
            $sqlArray = explode(";", $sql);
            if (is_array($sqlArray))
                foreach ($sqlArray as $val)
                    mysqli_query($link_db,$val);
        }
        $db = $this->getXml('../modules/' . $this->path . '../install/module.xml');
        return $db['version'];
    }

    /**



     */
    function getIni($path, $add = true) {
        $ini = $this->ModDir . $path . "/inc/config.ini";
        if (file_exists($ini)) {
            $SysValue = @parse_ini_file($ini, 1);

            if (!empty($SysValue['autoload']) and is_array($SysValue['autoload']))
                foreach ($SysValue['autoload'] as $k => $v)
                    if (!strstr($k, '#')) {
                        if ($add)
                            $this->ModValue['autoload'][$k] = $v;
                        else
                            unset($this->ModValue['autoload'][$k]);
                    }

            if (is_array($SysValue['unload']))
                foreach ($SysValue['unload'] as $k => $v)
                    if (!strstr($k, '#'))
                        $this->unload[] = $v;

            if (!empty($SysValue['core']) and is_array($SysValue['core'])) {
                foreach ($SysValue['core'] as $k => $v)
                    if (!strstr($k, '#')) {
                        if ($add)
                            $this->ModValue['core'][$k] = $v;
                        else
                            unset($this->ModValue['core'][$k]);
                    }
            }
            else
                $SysValue['core'] = null;

            if (!empty($SysValue['class']) and is_array($SysValue['class'])) {
                foreach ($SysValue['class'] as $k => $v)
                    if (!strstr($k, '#'))
                        $GLOBALS['SysValue']['class'][$k] = $v;
            }
            else
                $SysValue['class'] = null;

            if (!empty($SysValue['lang']) and is_array($SysValue['lang'])) {
                foreach ($SysValue['lang'] as $k => $v)
                    if (!strstr($k, '#'))
                        $GLOBALS['SysValue']['lang'][$k] = $v;
            }
            else
                $SysValue['lang'] = null;

            if (!empty($SysValue['admpanel']) and is_array($SysValue['admpanel']))
                foreach ($SysValue['admpanel'] as $k => $v)
                    if (!strstr($k, '#'))
                        $this->ModValue['admpanel'][][$k] = $v;

            if (!empty($SysValue['hook']) and is_array($SysValue['hook'])) {
                foreach ($SysValue['hook'] as $k => $v)
                    if (!strstr($k, '#')) {
                        if ($add)
                            $this->ModValue['hook'][$k][$path] = $v;
                        else
                            unset($this->ModValue['hook'][$k][$path]);
                    }
            }

            if (!empty($SysValue['templates']) and is_array($SysValue['templates'])) {
                $this->ModValue['templates'] = $SysValue['templates'];
                $GLOBALS['SysValue']['templates'][$path] = $SysValue['templates'];
            }


            if ($add) {
                $this->ModValue['base'][$path] = $SysValue['base'];
                $GLOBALS['SysValue']['base'][$path] = $SysValue['base'];
            } else {
                unset($this->ModValue['base'][$path]);
                unset($GLOBALS['SysValue']['base'][$path]);
            }

            $this->ModValue['class'] = $SysValue['class'];

            if (!empty($SysValue['field']) and is_array($SysValue['field']))
                $this->ModValue['field'][$path] = $SysValue['field'];
        }
    }

    function getKeyName() {
        return substr(md5($_SERVER["HTTP_USER_AGENT"]), 0, 5);
    }

    function crc16($data) {
        $crc = 0xFFFF;
        for ($i = 0; $i < strlen($data); $i++) {
            $x = (($crc >> 8) ^ ord($data[$i])) & 0xFF;
            $x ^= $x >> 4;
            $crc = (($crc << 8) ^ ($x << 12) ^ ($x << 5) ^ $x) & 0xFFFF;
        }
        return $crc;
    }

    function checkKey($key, $path) {
        $str = $path . str_replace('www.', '', $_SERVER['SERVER_NAME']);
        if ($this->crc16(substr($str, 0, 5)) . "-" . $this->crc16(substr($str, 5, 10)) . "-" . $this->crc16(substr($str, 10, 15)) == $key)
            return true;
    }

    function checkKeyBase($path = false) {

        if (!empty($path))
            $this->path = $path;

        if ($this->path) {
            $PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['modules_key']);
            $data = $PHPShopOrm->select(array('*'), array('path' => "='" . $this->path . "'",), false, array('limit' => 1));
            if (is_array($data)) {
                if ($data['verification'] != md5($data['path'] . $data['date'] . str_replace('www.', '', $_SERVER['SERVER_NAME']) . $data['key']) or $data['date'] < time()) {
                    return $data['date'];
                }
            }
            else
                return true;
        }

        elseif (!isset($_SESSION[$this->getKeyName()])) {
            $PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['modules_key']);
            $data = $PHPShopOrm->select(array('*'), false, false, array('limit' => 100));
            if (is_array($data)) {
                foreach ($data as $val) {
                    if ($val['verification'] != md5($val['path'] . $val['date'] . str_replace('www.', '', $_SERVER['SERVER_NAME']) . $val['key']) or $val['date'] < time()) {
                        $_SESSION[$this->getKeyName()][crc32($val['path'])] = time();
                    }
                }
            }
            if (empty($_SESSION[$this->getKeyName()])) {
                $_SESSION[$this->getKeyName()] = array();
            }
        }
    }

    function setKeyBase() {
        $PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['modules_key']);
        $update = array();
        $update['key_new'] = time();
        $update['date_new'] = 1537777023;
        $update['verification_new'] = md5($this->path . $update['date_new'] . str_replace('www.', '', $_SERVER['SERVER_NAME']) . $update['key_new']);
        $PHPShopOrm->update($update, array('path' => "='" . $this->path . "'"));
    }

    /**

     */
    function doLoad() {
        global $SysValue, $PHPShopSystem, $PHPShopNav;
        if (is_array($this->ModValue['autoload']))
            foreach ($this->ModValue['autoload'] as $k => $v) {
                if (file_exists($v))
                    require_once($v);
                else
                    echo("" . $k . "" . $v);
            }
    }

    /**


     * @return mixed
     */
    function doLoadPath($path) {
        global $SysValue;
        if (!empty($this->ModValue['core'][$path])) {
            if (is_file($this->ModValue['core'][$path])) {
                require_once($this->ModValue['core'][$path]);
                $classname = 'PHPShop' . ucfirst($SysValue['nav']['path']);

                if (class_exists($classname)) {
                    $PHPShopCore = new $classname ();
                    $PHPShopCore->loadActions();
                    return true;
                }
                else
                    echo PHPShopCore::setError($classname, "$classname.core.php");
            }
            else
                PHPShopCore::setError($path, "" . $path . "" . $this->ModValue['core'][$path]);
        }
        else
            return false;
    }

    /**


     * @return array
     */
    function getParam($param) {
        $param = explode(".", $param);
        if (count($param) > 2)
            return $this->ModValue[$param[0]][$param[1]][$param[2]];
        return $this->ModValue[$param[0]][$param[1]];
    }

    /**

     * @return array
     */
    function getModValue() {
        return $this->ModValue;
    }

    /**

     * <code>
     * // example:
     * $PHPShopModules->Parser(array('page'=>'market'),'catalog_page_1');
     * </code>


     * @return string
     */
    function Parser($preg, $TemplateName) {
        $file = newGetFile($GLOBALS['SysValue']['dir']['templates'] . chr(47) . $_SESSION['skin'] . chr(47) . $TemplateName);

        //
        foreach ($preg as $k => $v)
            $file = str_replace($k, $v, $file);

        $dis = newParser($file);
        return @$dis;
    }

    /**


     * @return array
     */
    function getXml($path) {
        PHPShopObj::loadClass("xml");


        $db = xml2array($path, false, true);


        if (count($db) > 1)
            return $db;
        else
            return $db[0];
    }

    /**


     * @return bool
     */
    function true_serial($serial) {
        if (preg_match('/^\d{5}-\d{5}-\d{5}$/', $serial)) {
            return true;
        }
    }

    function log($str, $var = false) {
        echo '<br>' . $str . '<br>';
        if ($var)
            print_r($var);
    }

    function setAdmHandler($path, $function_name, $data) {
        global $PHPShopGUI;
        $file = pathinfo($path, PATHINFO_FILENAME); // Moon add

        if (is_array($this->ModValue['admpanel']))
            foreach ($this->ModValue['admpanel'] as $mods) {
                $mod = $mods[$file];
                if ($mod)
                    if (is_file($this->ModDir . $mod)) {

                        include_once($this->ModDir . $mod);

                        if (is_array($addHandler))
                            $this->addHandler[$this->ModDir . $mod] = $addHandler;


                        if ((phpversion() * 1) >= '5.0') {
                            if (!empty($this->addHandler[$this->ModDir . $mod][$function_name]))
                                call_user_func($this->addHandler[$this->ModDir . $mod][$function_name], $data);
                        }
                        else {
                            //
                            if (is_array($this->addHandler[$this->ModDir . $mod]))
                                foreach ($this->addHandler[$this->ModDir . $mod] as $v => $k)
                                    $handler[strtolower($v)] = $k;

                            if (!empty($handler[$function_name])) {
                                call_user_func($handler[$function_name], $data);
                            }
                        }
                    }
                    else
                        $this->PHPShopOrm->setError('setAdmHandler', "" . $this->ModDir . $mod);
            }
    }

    /**






     */
    function setHookHandler($class_name, $function_name, $obj = false, $data = false, $rout = 'END') {

        $addHandler = null;

        //
        if (!empty($obj) and is_array($obj))
            $obj = &$obj[0];

        if ((phpversion() * 1) >= '5.0')
            $class_name = strtolower($class_name);

        //
        if (!empty($this->ModValue['hook'][$class_name]))
            foreach ($this->ModValue['hook'][$class_name] as $hook) {
                if (isset($hook))
                    if (is_file($hook)) {
                        include_once($hook);


                        if ((phpversion() * 1) >= '5.0') {

                            if (is_array($addHandler))
                                foreach ($addHandler as $v => $k)
                                    if (!strstr($v, '#'))
                                        $this->addHandler[$class_name][$v][$hook] = $k;
                        }
                        else {

                            //
                            if (!empty($addHandler) and is_array($addHandler))
                                foreach ($addHandler as $v => $k)
                                    if (!strstr($v, '#'))
                                        $this->addHandler[$class_name][strtolower($v)][$hook] = $k;
                        }
                    }
            }

        if (!empty($this->addHandler[$class_name][$function_name]) and is_array($this->addHandler[$class_name][$function_name])) {
            $user_func_result = null;
            foreach ($this->addHandler[$class_name][$function_name] as $hook_function_name) {

                //
                $time = microtime(true);

                $user_func_result = call_user_func_array($hook_function_name, array(&$obj, &$data, $rout));

                //
                $seconds = round(microtime(true) - $time, 6);

                //
                $this->handlerDone[$class_name][$hook_function_name][$rout] = $seconds;
            }

            //
            if (!empty($user_func_result))
                return $user_func_result;
        }
    }

    /**

     * @return bool
     */
    function memory_check($class_name, $function_name) {
        if ($this->memory) {
            if ($this->memory_get($class_name . '.' . $function_name) != 1)
                return true;
        }
        else
            return true;
    }

    /**



     */
    function memory_set($param, $value) {
        if (!empty($this->memory)) {
            $param = explode(".", $param);
            $_SESSION['Memory'][__CLASS__][$param[0]][$param[1]] = $value;
            $_SESSION['Memory'][__CLASS__]['time'] = time();
        }
    }

    /**


     * @return
     */
    function memory_get($param) {
        $this->memory_clean();
        if (!empty($this->memory)) {
            $param = explode(".", $param);
            if (isset($_SESSION['Memory'][__CLASS__][$param[0]][$param[1]])) {
                return $_SESSION['Memory'][__CLASS__][$param[0]][$param[1]];
            }
        }
    }

    /**


     */
    function memory_clean($clean_now = false) {
        if (!empty($clean_now))
            unset($_SESSION['Memory'][__CLASS__]);
        elseif ($_SESSION['Memory'][__CLASS__]['time'] < (time() - 60 * 10))
            unset($_SESSION['Memory'][__CLASS__]);
    }

    /**


     */
    function checkInstall($path) {
        $install = $this->ModValue['base'][$path];
        if (empty($install))
            exit('' . ucfirst($path) . '');
    }

}

?>
API documentation generated by ApiGen