Exemplo n.º 1
0
 public static function getItemUrl(&$item)
 {
     $gn_id = $item['gn_id'];
     $gn_title = $item['gn_title'];
     $friendly_title = osc_sanitizeString(osc_apply_filter('slug', $gn_title));
     $item_url = GZ_NEWS_URL . 'pages/item.php';
     if (self::isModRewriteEnabled()) {
         $item_url = osc_base_url() . "news/read/{$gn_id}/{$friendly_title}.html";
     } else {
         $item_url = $item_url . "?i={$gn_id}&title={$friendly_title}";
     }
     return $item_url;
 }
Exemplo n.º 2
0
 public function insert($fields, $aFieldsDescription = null)
 {
     $columns = implode(', ', array_keys($fields));
     $set = "";
     foreach ($fields as $value) {
         if ($set != "") {
             $set .= ", ";
         }
         $set .= $this->formatValue($value);
     }
     $sql = 'INSERT INTO ' . $this->getTableName() . ' (' . $columns . ') VALUES (' . $set . ')';
     $this->conn->osc_dbExec($sql);
     $category_id = $this->conn->get_last_id();
     foreach ($aFieldsDescription as $k => $fieldsDescription) {
         $fieldsDescription['fk_i_category_id'] = $category_id;
         $fieldsDescription['fk_c_locale_code'] = $k;
         $fieldsDescription['s_slug'] = osc_sanitizeString(osc_apply_filter('slug', $fieldsDescription['s_name']));
         $columns = implode(', ', array_keys($fieldsDescription));
         $set = "";
         foreach ($fieldsDescription as $value) {
             if ($set != "") {
                 $set .= ", ";
             }
             $set .= $this->formatValue($value);
         }
         $sql = 'INSERT INTO ' . $this->getTableDescriptionName() . ' (' . $columns . ') VALUES (' . $set . ')';
         $this->conn->osc_dbExec($sql);
     }
 }
Exemplo n.º 3
0
/**
 * Gets the url of current "list city""
 *
 * @return string
 */
function osc_list_city_url()
{
    if (osc_rewrite_enabled()) {
        $url = osc_base_url();
        if (osc_get_preference('seo_url_search_prefix') != '') {
            $url .= osc_get_preference('seo_url_search_prefix') . '/';
        }
        $url .= osc_sanitizeString(osc_list_city_name()) . '-c' . osc_list_city_id();
        return $url;
    } else {
        return osc_search_url(array('sCity' => osc_list_city_id()));
    }
}
Exemplo n.º 4
0
/**
 * Gets search url given params
 *
 * @params array $params
 * @return string
 */
function osc_search_url($params = null)
{
    if (is_array($params)) {
        osc_prune_array($params);
    }
    $countP = count($params);
    if ($countP == 0) {
        $params['page'] = 'search';
    }
    $base_url = osc_base_url();
    $http_url = osc_is_ssl() ? "https://" : "http://";
    if (osc_subdomain_type() == 'category' && isset($params['sCategory'])) {
        if ($params['sCategory'] != Params::getParam('sCategory')) {
            if (is_array($params['sCategory'])) {
                $params['sCategory'] = implode(",", $params['sCategory']);
            }
            if ($params['sCategory'] != '' && strpos($params['sCategory'], ",") === false) {
                if (is_numeric($params['sCategory'])) {
                    $category = Category::newInstance()->findByPrimaryKey($params['sCategory']);
                } else {
                    $category = Category::newInstance()->findBySlug($params['sCategory']);
                }
                if (isset($category['s_slug'])) {
                    $base_url = $http_url . $category['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL;
                    unset($params['sCategory']);
                }
            }
        } else {
            if (osc_is_subdomain()) {
                unset($params['sCategory']);
            }
        }
    } else {
        if (osc_subdomain_type() == 'country' && isset($params['sCountry'])) {
            if ($params['sCountry'] != Params::getParam('sCountry')) {
                if (is_array($params['sCountry'])) {
                    $params['sCountry'] = implode(",", $params['sCountry']);
                }
                if ($params['sCountry'] != '' && strpos($params['sCountry'], ",") === false) {
                    if (is_numeric($params['sCountry'])) {
                        $country = Country::newInstance()->findByPrimaryKey($params['sCountry']);
                    } else {
                        $country = Country::newInstance()->findByCode($params['sCountry']);
                    }
                    if (isset($country['s_slug'])) {
                        $base_url = $http_url . $country['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL;
                        unset($params['sCountry']);
                    }
                }
            } else {
                if (osc_is_subdomain()) {
                    unset($params['sCountry']);
                }
            }
        } else {
            if (osc_subdomain_type() == 'region' && isset($params['sRegion'])) {
                if ($params['sRegion'] != Params::getParam('sRegion')) {
                    if (is_array($params['sRegion'])) {
                        $params['sRegion'] = implode(",", $params['sRegion']);
                    }
                    if ($params['sRegion'] != '' && strpos($params['sRegion'], ",") === false) {
                        if (is_numeric($params['sRegion'])) {
                            $region = Region::newInstance()->findByPrimaryKey($params['sRegion']);
                        } else {
                            $region = Region::newInstance()->findByName($params['sRegion']);
                        }
                        if (isset($region['s_slug'])) {
                            $base_url = $http_url . $region['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL;
                            unset($params['sRegion']);
                        }
                    }
                } else {
                    if (osc_is_subdomain()) {
                        unset($params['sRegion']);
                    }
                }
            } else {
                if (osc_subdomain_type() == 'city' && isset($params['sCity'])) {
                    if ($params['sCity'] != Params::getParam('sCity')) {
                        if (is_array($params['sCity'])) {
                            $params['sCity'] = implode(",", $params['sCity']);
                        }
                        if ($params['sCity'] != '' && strpos($params['sCity'], ",") === false) {
                            if (is_numeric($params['sCity'])) {
                                $city = City::newInstance()->findByPrimaryKey($params['sCity']);
                            } else {
                                $city = City::newInstance()->findByName($params['sCity']);
                            }
                            if (isset($city['s_slug'])) {
                                $base_url = $http_url . $city['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL;
                                unset($params['sCity']);
                            }
                        }
                    } else {
                        if (osc_is_subdomain()) {
                            unset($params['sCity']);
                        }
                    }
                } else {
                    if (osc_subdomain_type() == 'user' && isset($params['sUser'])) {
                        if ($params['sUser'] != Params::getParam('sUser')) {
                            if (is_array($params['sUser'])) {
                                $params['sUser'] = implode(",", $params['sUser']);
                            }
                            if ($params['sUser'] != '' && strpos($params['sUser'], ",") === false) {
                                if (is_numeric($params['sUser'])) {
                                    $user = User::newInstance()->findByPrimaryKey($params['sUser']);
                                } else {
                                    $user = User::newInstance()->findByUsername($params['sUser']);
                                }
                                if (isset($user['s_username'])) {
                                    $base_url = $http_url . $user['s_username'] . "." . osc_subdomain_host() . REL_WEB_URL;
                                    unset($params['sUser']);
                                }
                            }
                        } else {
                            if (osc_is_subdomain()) {
                                unset($params['sUser']);
                            }
                        }
                    }
                }
            }
        }
    }
    $countP = count($params);
    if ($countP == 0) {
        return $base_url;
    }
    unset($params['page']);
    $countP = count($params);
    if (osc_rewrite_enabled()) {
        $url = $base_url . osc_get_preference('rewrite_search_url');
        // CANONICAL URLS
        if (isset($params['sCategory']) && !is_array($params['sCategory']) && strpos($params['sCategory'], ',') === false && ($countP == 1 || $countP == 2 && isset($params['iPage']))) {
            if (osc_category_id() == $params['sCategory']) {
                $category['pk_i_id'] = osc_category_id();
                $category['s_slug'] = osc_category_slug();
            } else {
                if (is_numeric($params['sCategory'])) {
                    $category = Category::newInstance()->findByPrimaryKey($params['sCategory']);
                } else {
                    $category = Category::newInstance()->findBySlug($params['sCategory']);
                }
            }
            if (isset($category['pk_i_id'])) {
                $url = osc_get_preference('rewrite_cat_url');
                if (preg_match('|{CATEGORIES}|', $url)) {
                    $categories = Category::newInstance()->hierarchy($category['pk_i_id']);
                    $sanitized_categories = array();
                    $mCat = Category::newInstance();
                    for ($i = count($categories); $i > 0; $i--) {
                        $tmpcat = $mCat->findByPrimaryKey($categories[$i - 1]['pk_i_id']);
                        $sanitized_categories[] = $tmpcat['s_slug'];
                    }
                    $url = str_replace('{CATEGORIES}', implode("/", $sanitized_categories), $url);
                }
                $seo_prefix = '';
                if (osc_get_preference('seo_url_search_prefix') != '') {
                    $seo_prefix = osc_get_preference('seo_url_search_prefix') . '/';
                }
                $url = str_replace('{CATEGORY_NAME}', $category['s_slug'], $url);
                // DEPRECATED : CATEGORY_SLUG is going to be removed in 3.4
                $url = str_replace('{CATEGORY_SLUG}', $category['s_slug'], $url);
                $url = str_replace('{CATEGORY_ID}', $category['pk_i_id'], $url);
            } else {
                // Search by a category which does not exists (by form)
                // TODO CHANGE TO NEW ROUTES!!
                return $base_url . 'index.php?page=search&sCategory=' . urlencode($params['sCategory']);
            }
            if (isset($params['iPage']) && $params['iPage'] != '' && $params['iPage'] != 1) {
                $url .= '/' . $params['iPage'];
            }
            $url = $base_url . $seo_prefix . $url;
        } else {
            if (isset($params['sRegion']) && is_string($params['sRegion']) && strpos($params['sRegion'], ',') === false && ($countP == 1 || $countP == 2 && (isset($params['iPage']) || isset($params['sCategory'])) || $countP == 3 && isset($params['iPage']) && isset($params['sCategory']))) {
                $url = $base_url;
                if (osc_get_preference('seo_url_search_prefix') != '') {
                    $url .= osc_get_preference('seo_url_search_prefix') . '/';
                }
                if (isset($params['sCategory'])) {
                    $_auxSlug = _aux_search_category_slug($params['sCategory']);
                    if ($_auxSlug != '') {
                        $url .= $_auxSlug . '_';
                    }
                }
                if (isset($params['sRegion'])) {
                    if (osc_list_region_id() == $params['sRegion']) {
                        $url .= osc_sanitizeString(osc_list_region_slug()) . '-r' . osc_list_region_id();
                    } else {
                        if (is_numeric($params['sRegion'])) {
                            $region = Region::newInstance()->findByPrimaryKey($params['sRegion']);
                        } else {
                            $region = Region::newInstance()->findByName($params['sRegion']);
                        }
                        if (isset($region['s_slug'])) {
                            $url .= osc_sanitizeString($region['s_slug']) . '-r' . $region['pk_i_id'];
                        } else {
                            // Search by a region which does not exists (by form)
                            // TODO CHANGE TO NEW ROUTES!!
                            return $url . 'index.php?page=search&sRegion=' . urlencode($params['sRegion']);
                        }
                    }
                }
                if (isset($params['iPage']) && $params['iPage'] != '' && $params['iPage'] != 1) {
                    $url .= '/' . $params['iPage'];
                }
            } else {
                if (isset($params['sCity']) && !is_array($params['sCity']) && strpos($params['sCity'], ',') === false && ($countP == 1 || $countP == 2 && (isset($params['iPage']) || isset($params['sCategory'])) || $countP == 3 && isset($params['iPage']) && isset($params['sCategory']))) {
                    $url = $base_url;
                    if (osc_get_preference('seo_url_search_prefix') != '') {
                        $url .= osc_get_preference('seo_url_search_prefix') . '/';
                    }
                    if (isset($params['sCategory'])) {
                        $_auxSlug = _aux_search_category_slug($params['sCategory']);
                        if ($_auxSlug != '') {
                            $url .= $_auxSlug . '_';
                        }
                    }
                    if (isset($params['sCity'])) {
                        if (osc_list_city_id() == $params['sCity']) {
                            $url .= osc_sanitizeString(osc_list_city_slug()) . '-c' . osc_list_city_id();
                        } else {
                            if (is_numeric($params['sCity'])) {
                                $city = City::newInstance()->findByPrimaryKey($params['sCity']);
                            } else {
                                $city = City::newInstance()->findByName($params['sCity']);
                            }
                            if (isset($city['s_slug'])) {
                                $url .= osc_sanitizeString($city['s_slug']) . '-c' . $city['pk_i_id'];
                            } else {
                                // Search by a city which does not exists (by form)
                                // TODO CHANGE TO NEW ROUTES!!
                                return $url . 'index.php?page=search&sCity=' . urlencode($params['sCity']);
                            }
                        }
                    }
                    if (isset($params['iPage']) && $params['iPage'] != '' && $params['iPage'] != 1) {
                        $url .= '/' . $params['iPage'];
                    }
                } else {
                    if ($params != null && is_array($params)) {
                        foreach ($params as $k => $v) {
                            switch ($k) {
                                case 'sCountry':
                                    $k = osc_get_preference('rewrite_search_country');
                                    break;
                                case 'sRegion':
                                    $k = osc_get_preference('rewrite_search_region');
                                    break;
                                case 'sCity':
                                    $k = osc_get_preference('rewrite_search_city');
                                    break;
                                case 'sCityArea':
                                    $k = osc_get_preference('rewrite_search_city_area');
                                    break;
                                case 'sCategory':
                                    $k = osc_get_preference('rewrite_search_category');
                                    if (is_array($v)) {
                                        $v = implode(",", $v);
                                    }
                                    break;
                                case 'sUser':
                                    $k = osc_get_preference('rewrite_search_user');
                                    if (is_array($v)) {
                                        $v = implode(",", $v);
                                    }
                                    break;
                                case 'sPattern':
                                    $k = osc_get_preference('rewrite_search_pattern');
                                    break;
                                case 'meta':
                                    // meta(@id),value/meta(@id),value2/...
                                    foreach ($v as $key => $value) {
                                        if (is_array($value)) {
                                            foreach ($value as $_key => $_value) {
                                                if ($value != '') {
                                                    $url .= '/meta' . $key . '-' . $_key . ',' . urlencode($_value);
                                                }
                                            }
                                        } else {
                                            if ($value != '') {
                                                $url .= '/meta' . $key . ',' . urlencode($value);
                                            }
                                        }
                                    }
                                    break;
                                default:
                                    break;
                            }
                            if (!is_array($v) && $v != '') {
                                $url .= "/" . $k . "," . urlencode($v);
                            }
                        }
                    }
                }
            }
        }
    } else {
        $url = $base_url . 'index.php?page=search';
        if ($params != null && is_array($params)) {
            foreach ($params as $k => $v) {
                if ($k == 'meta') {
                    if (is_array($v)) {
                        foreach ($v as $_k => $aux) {
                            if (is_array($aux)) {
                                foreach (array_keys($aux) as $aux_k) {
                                    $url .= "&" . $k . "[{$_k}][{$aux_k}]=" . urlencode($aux[$aux_k]);
                                }
                            } else {
                                $url .= "&" . $_k . "[]=" . urlencode($aux);
                            }
                        }
                    }
                } else {
                    if (is_array($v)) {
                        $v = implode(",", $v);
                    }
                    $url .= "&" . $k . "=" . urlencode($v);
                }
            }
        }
    }
    return str_replace('%2C', ',', $url);
}
Exemplo n.º 5
0
/**
 * Create automatically the url of the item details page
 *
 * @param string $locale
 * @return string
 */
function osc_premium_url($locale = '')
{
    if (osc_rewrite_enabled()) {
        $sanitized_categories = array();
        $cat = Category::newInstance()->hierarchy(osc_premium_category_id());
        for ($i = count($cat); $i > 0; $i--) {
            $sanitized_categories[] = $cat[$i - 1]['s_slug'];
        }
        $url = str_replace('{CATEGORIES}', implode("/", $sanitized_categories), str_replace('{ITEM_ID}', osc_premium_id(), str_replace('{ITEM_TITLE}', osc_sanitizeString(osc_premium_title()), osc_get_preference('rewrite_item_url'))));
        if ($locale != '') {
            $path = osc_base_url() . $locale . "/" . $url;
        } else {
            $path = osc_base_url() . $url;
        }
    } else {
        $path = osc_item_url_ns(osc_premium_id(), $locale);
    }
    return $path;
}
Exemplo n.º 6
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'edit':
             if (Params::getParam("id") == '') {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             }
             $this->_exportVariableToView("page", $this->pageManager->findByPrimaryKey(Params::getParam("id")));
             $this->doView("pages/frm.php");
             break;
         case 'edit_post':
             $id = Params::getParam("id");
             $s_internal_name = Params::getParam("s_internal_name");
             // sanitize internal name
             $s_internal_name = osc_sanitizeString($s_internal_name);
             if (!WebThemes::newInstance()->isValidPage($s_internal_name)) {
                 osc_add_flash_error_message(_m('You have to set a different internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages?action=edit&id=" . $id);
             }
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray('', false);
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             if ($not_empty) {
                 foreach ($aFieldsDescription as $k => $_data) {
                     $this->pageManager->updateDescription($id, $k, $_data['s_title'], $_data['s_text']);
                 }
                 if (!$this->pageManager->internalNameExists($id, $s_internal_name)) {
                     if (!$this->pageManager->isIndelible($id)) {
                         $this->pageManager->updateInternalName($id, $s_internal_name);
                     }
                     osc_add_flash_ok_message(_m('The page has been updated'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
                 }
                 osc_add_flash_error_message(_m("You can't repeat internal name"), 'admin');
             } else {
                 osc_add_flash_error_message(_m("The page couldn't be updated, at least one title should not be empty"), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages?action=edit&id=" . $id);
             break;
         case 'add':
             $this->_exportVariableToView("page", array());
             $this->doView("pages/frm.php");
             break;
         case 'add_post':
             // setForm just in case the form fails
             foreach (Params::getParamsAsArray('', false) as $k => $v) {
                 Session::newInstance()->_setForm($k, $v);
             }
             $s_internal_name = Params::getParam("s_internal_name");
             // sanitize internal name
             $s_internal_name = osc_sanitizeString($s_internal_name);
             if ($s_internal_name == '') {
                 osc_add_flash_error_message(_m('You have to set an internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             }
             if (!WebThemes::newInstance()->isValidPage($s_internal_name)) {
                 osc_add_flash_error_message(_m('You have to set a different internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             }
             $page = $this->pageManager->findByInternalName($s_internal_name);
             if (!isset($page['pk_i_id'])) {
                 $aFields = array('s_internal_name' => $s_internal_name, 'b_indelible' => '0');
                 $aFieldsDescription = array();
                 $postParams = Params::getParamsAsArray('', false);
                 $not_empty = false;
                 foreach ($postParams as $k => $v) {
                     if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                         if ($m[2] == 's_title' && $v != '') {
                             $not_empty = true;
                         }
                         $aFieldsDescription[$m[1]][$m[2]] = $v;
                     }
                 }
                 if ($not_empty) {
                     $result = $this->pageManager->insert($aFields, $aFieldsDescription);
                     osc_add_flash_ok_message(_m('The page has been added'), 'admin');
                 } else {
                     osc_add_flash_error_message(_m("The page couldn't be added, at least one title should not be empty"), 'admin');
                 }
             } else {
                 osc_add_flash_error_message(_m("Oops! That internal name is already in use. We can't made the changes"), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             break;
         case 'delete':
             $id = Params::getParam("id");
             $page_deleted_correcty = 0;
             $page_deleted_error = 0;
             $page_indelible = 0;
             if (!is_array($id)) {
                 $id = array($id);
             }
             foreach ($id as $_id) {
                 $result = (int) $this->pageManager->deleteByPrimaryKey($_id);
                 switch ($result) {
                     case -1:
                         $page_indelible++;
                         break;
                     case 0:
                         $page_deleted_error++;
                         break;
                     case 1:
                         $page_deleted_correcty++;
                 }
             }
             if ($page_indelible > 0) {
                 if ($page_indelible == 1) {
                     osc_add_flash_error_message(_m("One page can't be deleted because it is indelible"), 'admin');
                 } else {
                     osc_add_flash_error_message(sprintf(_m("%s pages couldn't be deleted because are indelible"), $page_indelible), 'admin');
                 }
             }
             if ($page_deleted_error > 0) {
                 if ($page_deleted_error == 1) {
                     osc_add_flash_error_message(_m("One page couldn't be deleted"), 'admin');
                 } else {
                     osc_add_flash_error_message(sprintf(_m("%s pages couldn't be deleted"), $page_deleted_error), 'admin');
                 }
             }
             if ($page_deleted_correcty > 0) {
                 if ($page_deleted_correcty == 1) {
                     osc_add_flash_ok_message(_m('One page has been deleted correctly'), 'admin');
                 } else {
                     osc_add_flash_ok_message(sprintf(_m('%s pages have been deleted correctly'), $page_deleted_correcty), 'admin');
                 }
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             break;
         default:
             $this->_exportVariableToView("prefLocale", osc_current_admin_locale());
             $this->_exportVariableToView("pages", $this->pageManager->listAll(0));
             $this->doView("pages/index.php");
     }
 }
Exemplo n.º 7
0
 /**
  * Inser a new category
  *
  * @access public
  * @since unknown
  * @param array $fields
  * @param array $aFieldsDescriptions
  */
 public function insert($fields, $aFieldsDescription = null)
 {
     $this->dao->insert($this->getTableName(), $fields);
     $category_id = $this->dao->insertedId();
     foreach ($aFieldsDescription as $k => $fieldsDescription) {
         $fieldsDescription['fk_i_category_id'] = $category_id;
         $fieldsDescription['fk_c_locale_code'] = $k;
         $slug_tmp = $slug = osc_sanitizeString(osc_apply_filter('slug', $fieldsDescription['s_name']));
         $slug_unique = 1;
         while (true) {
             if (!$this->findBySlug($slug)) {
                 break;
             } else {
                 $slug = $slug_tmp . "_" . $slug_unique;
                 $slug_unique++;
             }
         }
         $fieldsDescription['s_slug'] = $slug;
         $this->dao->insert(DB_TABLE_PREFIX . 't_category_description', $fieldsDescription);
     }
     return $category_id;
 }
Exemplo n.º 8
0
/**
 * Sanitize a string.
 *
 * @param string $value value to sanitize
 * @return string sanitized
 */
function osc_sanitize_string($value)
{
    return osc_sanitizeString($value);
}
Exemplo n.º 9
0
function osc_calculate_location_slug($type)
{
    $field = 'pk_i_id';
    switch ($type) {
        case 'country':
            $manager = Country::newInstance();
            $field = 'pk_c_code';
            break;
        case 'region':
            $manager = Region::newInstance();
            break;
        case 'city':
            $manager = City::newInstance();
            break;
        default:
            return false;
            break;
    }
    $locations = $manager->listByEmptySlug();
    $locations_changed = 0;
    foreach ($locations as $location) {
        $slug_tmp = $slug = osc_sanitizeString($location['s_name']);
        $slug_unique = 1;
        while (true) {
            $location_slug = $manager->findBySlug($slug);
            if (!isset($location_slug[$field])) {
                break;
            } else {
                $slug = $slug_tmp . '-' . $slug_unique;
                $slug_unique++;
            }
        }
        $locations_changed += $manager->update(array('s_slug' => $slug), array($field => $location[$field]));
    }
    return $locations_changed;
}
Exemplo n.º 10
0
/**
 * Create automatically the url of the item details page
 *
 * @return string
 */
function osc_item_url($locale = '')
{
    if (osc_rewrite_enabled()) {
        $sanitized_title = osc_sanitizeString(osc_item_title());
        $sanitized_category = '';
        $cat = Category::newInstance()->hierarchy(osc_item_category_id());
        for ($i = count($cat); $i > 0; $i--) {
            $sanitized_category .= $cat[$i - 1]['s_slug'] . '/';
        }
        if ($locale != '') {
            $path = osc_base_url() . sprintf('%s_%s%s_%d', $locale, $sanitized_category, $sanitized_title, osc_item_id());
        } else {
            $path = osc_base_url() . sprintf('%s%s_%d', $sanitized_category, $sanitized_title, osc_item_id());
        }
    } else {
        //$path = osc_base_url(true) . sprintf('?page=item&id=%d', osc_item_id()) ;
        $path = osc_item_url_ns(osc_item_id(), $locale);
    }
    return $path;
}
Exemplo n.º 11
0
        function doModel()
        {
            // calling the locations settings view
            $location_action = Params::getParam('type');
            $mCountries = new Country();

            switch ($location_action) {
                case('add_country'):    // add country
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $countryCode = strtoupper(Params::getParam('c_country'));
                                        $countryName = Params::getParam('country');
                                        $exists = $mCountries->findByCode($countryCode);
                                        if(isset($exists['s_name'])) {
                                            osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $countryName), 'admin');
                                        } else {
                                            if(Params::getParam('c_manual')==1) {
                                                $mCountries->insert(array('pk_c_code' => $countryCode,
                                                                        's_name' => $countryName));
                                                osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin');
                                            } else {
                                                if(!osc_validate_min($countryCode, 1) || !osc_validate_min($countryName, 1)) {
                                                    osc_add_flash_error_message(_m('Country code and name should have at least two characters'), 'admin');
                                                } else {
                                                    $data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=country&term=' . urlencode($countryCode) );

                                                    if($data_sql!='') {
                                                        $conn = DBConnectionClass::newInstance();
                                                        $c_db = $conn->getOsclassDb();
                                                        $comm = new DBCommandClass($c_db);
                                                        $comm->query("SET FOREIGN_KEY_CHECKS = 0");
                                                        $comm->importSQL($data_sql);
                                                        $comm->query("SET FOREIGN_KEY_CHECKS = 1");
                                                    } else {
                                                        $mCountries->insert(array('pk_c_code' => $countryCode,
                                                                                's_name' => $countryName));
                                                    }
                                                    osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin');
                                                }
                                            }
                                        }
                                        osc_calculate_location_slug(osc_subdomain_type());
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                break;
                case('edit_country'):   // edit country
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        if(!osc_validate_min(Params::getParam('e_country'), 1)) {
                                            osc_add_flash_error_message(_m('Country name cannot be blank'), 'admin');
                                        } else {
                                            $name = Params::getParam('e_country');
                                            $slug = Params::getParam('e_country_slug');
                                            if($slug=='') {
                                                $slug_tmp = $slug = osc_sanitizeString($name);
                                            } else {
                                                $exists = $mCountries->findBySlug($slug);
                                                if(isset($exists['s_slug']) && $exists['pk_c_code']!=Params::getParam('country_code')) {
                                                    $slug_tmp = $slug = osc_sanitizeString($name);
                                                } else {
                                                    $slug_tmp = $slug = osc_sanitizeString($slug);
                                                }
                                            }
                                            $slug_unique = 1;
                                            while(true) {
                                                $location_slug = $mCountries->findBySlug($slug);
                                                if(isset($location_slug['s_slug']) && $location_slug['pk_c_code']!=Params::getParam('country_code')) {
                                                    $slug = $slug_tmp . '-' . $slug_unique;
                                                    $slug_unique++;
                                                } else {
                                                    break;
                                                }
                                            }

                                            $ok = $mCountries->update(array('s_name'=> $name, 's_slug' => $slug), array('pk_c_code' => Params::getParam('country_code')));

                                            if( $ok ) {
                                                osc_add_flash_ok_message(_m('Country has been edited'), 'admin');
                                            } else {
                                                osc_add_flash_error_message(_m('There were some problems editing the country'), 'admin');
                                            }
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                break;
                case('delete_country'): // delete country
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $countryIds = Params::getParam('id');

                                        if(is_array($countryIds)) {
                                            $locations = 0;
                                            $del_locations = 0;
                                            foreach($countryIds as $countryId) {
                                                $ok = $mCountries->deleteByPrimaryKey($countryId);
                                            }
                                            if($ok==0) {
                                                $del_locations++;
                                            } else {
                                                $locations += $ok;
                                            }
                                            if($locations==0) {
                                                osc_add_flash_ok_message(sprintf(_n('One location has been deleted', '%s locations have been deleted', $del_locations), $del_locations), 'admin');
                                            } else {
                                                osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin');
                                            }
                                        } else {
                                            osc_add_flash_error_message(_m('No country was selected'), 'admin');
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                break;
                case('add_region'):     // add region
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        if( !Params::getParam('r_manual') ) {
                                            $regionId    = Params::getParam('region_id');
                                            $regionName  = Params::getParam('region');
                                            if($regionId!='') {
                                                $data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=region&term=' . urlencode($regionId) );

                                                $conn = DBConnectionClass::newInstance();
                                                $c_db = $conn->getOsclassDb();
                                                $comm = new DBCommandClass($c_db);
                                                $comm->query("SET FOREIGN_KEY_CHECKS = 0");
                                                $comm->importSQL($data_sql);
                                                $comm->query("SET FOREIGN_KEY_CHECKS = 1");
                                                osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin');
                                            } else {
                                                osc_add_flash_error_message(sprintf(_m("%s can't be added"), $regionName), 'admin');
                                            }

                                        } else {
                                            $mRegions    = new Region();
                                            $regionName  = Params::getParam('region');
                                            $countryCode = Params::getParam('country_c_parent');
                                            $country     = Country::newInstance()->findByCode($countryCode);

                                            if(!osc_validate_min($regionName, 1)) {
                                                osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin');
                                            } else {
                                                $exists = $mRegions->findByName($regionName, $countryCode);
                                                if(!isset($exists['s_name'])) {
                                                    $data = array('fk_c_country_code' => $countryCode
                                                                ,'s_name' => $regionName);
                                                    $mRegions->insert($data);
                                                    $id = $mRegions->dao->insertedId();
                                                    RegionStats::newInstance()->setNumItems($id, 0);

                                                    osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin');
                                                } else {
                                                    osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $regionName), 'admin');
                                                }
                                            }
                                        }
                                        osc_calculate_location_slug(osc_subdomain_type());
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$countryCode."&country=".@$country['s_name']);
                break;
                case('edit_region'):    // edit region
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $mRegions  = new Region();
                                        $newRegion = Params::getParam('e_region');
                                        $regionId  = Params::getParam('region_id');

                                        if(!osc_validate_min($newRegion, 1)) {
                                            osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin');
                                        } else {
                                            $exists = $mRegions->findByName($newRegion);
                                            if(!isset($exists['pk_i_id']) || $exists['pk_i_id']==$regionId) {
                                                if($regionId != '') {
                                                    $aRegion = $mRegions->findByPrimaryKey($regionId);
                                                    $country = Country::newInstance()->findByCode($aRegion['fk_c_country_code']);

                                                    $name = $newRegion;
                                                    $slug = Params::getParam('e_region_slug');
                                                    if($slug=='') {
                                                        $slug_tmp = $slug = osc_sanitizeString($name);
                                                    } else {
                                                        $exists = $mRegions->findBySlug($slug);
                                                        if(isset($exists['s_slug']) && $exists['pk_i_id']!=$regionId) {
                                                            $slug_tmp = $slug = osc_sanitizeString($name);
                                                        } else {
                                                            $slug_tmp = $slug = osc_sanitizeString($slug);
                                                        }
                                                    }
                                                    $slug_unique = 1;
                                                    while(true) {
                                                        $location_slug = $mRegions->findBySlug($slug);
                                                        if(isset($location_slug['s_slug']) && $location_slug['pk_i_id']!=$regionId) {
                                                            $slug = $slug_tmp . '-' . $slug_unique;
                                                            $slug_unique++;
                                                        } else {
                                                            break;
                                                        }
                                                    }

                                                    $mRegions->update(array('s_name' => $newRegion, 's_slug' => $slug)
                                                                     ,array('pk_i_id' => $regionId));
                                                    ItemLocation::newInstance()->update(
                                                        array('s_region'       => $newRegion),
                                                        array('fk_i_region_id' => $regionId)
                                                    );
                                                    osc_add_flash_ok_message(sprintf(_m('%s has been edited'), $newRegion), 'admin');
                                                }
                                            } else {
                                                osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newRegion), 'admin');
                                            }
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']);
                break;
                case('delete_region'):  // delete region
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $mRegion  = new Region();
                                        $regionIds = Params::getParam('id');

                                        if(is_array($regionIds)) {
                                            $locations = 0;
                                            $del_locations = 0;
                                            if(count($regionIds)>0) {
                                                $region = $mRegion->findByPrimaryKey($regionIds[0]);
                                                $country = Country::newInstance()->findByCode($region['fk_c_country_code']);
                                                foreach($regionIds as $regionId) {
                                                    if($regionId != '') {
                                                        $ok = $mRegion->deleteByPrimaryKey($regionId);
                                                        if($ok==0) {
                                                            $del_locations++;
                                                        } else {
                                                            $locations += $ok;
                                                        }
                                                    }
                                                }
                                            }
                                            if($locations==0) {
                                                osc_add_flash_ok_message(sprintf(_n('One location has been deleted', '%s locations have been deleted', $del_locations), $del_locations), 'admin');
                                            } else {
                                                osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin');
                                            }
                                        } else {
                                            osc_add_flash_error_message(_m('No region was selected'), 'admin');
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']);
                break;
                case('add_city'):       // add city
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $regionId    = Params::getParam('region_parent');
                                        $countryCode = Params::getParam('country_c_parent');
                                        $mRegion     = new Region();
                                        $region = $mRegion->findByPrimaryKey($regionId);
                                        $country = Country::newInstance()->findByCode($region['fk_c_country_code']);
                                        if( !Params::getParam('ci_manual') ) {
                                            $cityId    = Params::getParam('city_id');
                                            $cityName  = Params::getParam('city');
                                            if($cityId!='') {
                                                $data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=city&term=' . urlencode($cityId) );

                                                $conn = DBConnectionClass::newInstance();
                                                $c_db = $conn->getOsclassDb();
                                                $comm = new DBCommandClass($c_db);
                                                $comm->query("SET FOREIGN_KEY_CHECKS = 0");
                                                $comm->importSQL($data_sql);
                                                $comm->query("SET FOREIGN_KEY_CHECKS = 1");
                                                osc_add_flash_ok_message(sprintf(_m('%s has been added as a new city'), $cityName), 'admin');
                                            } else {
                                                osc_add_flash_error_message(sprintf(_m("%s can't be added"), $cityName), 'admin');
                                            }

                                        } else {
                                            $mCities     = new City();
                                            $newCity     = Params::getParam('city');

                                            if(!osc_validate_min($newCity, 1)) {
                                                osc_add_flash_error_message(_m('New city name cannot be blank'), 'admin');
                                            } else {
                                                $exists = $mCities->findByName($newCity, $regionId);
                                                if(!isset($exists['s_name'])) {
                                                    $mCities->insert(array('fk_i_region_id'    => $regionId
                                                                        ,'s_name'            => $newCity
                                                                        ,'fk_c_country_code' => $countryCode));
                                                    $id = $mCities->dao->insertedId();
                                                    CityStats::newInstance()->setNumItems($id, 0);

                                                    osc_add_flash_ok_message(sprintf(_m('%s has been added as a new city'), $newCity), 'admin');
                                                } else {
                                                    osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newCity), 'admin');
                                                }
                                            }
                                        }
                                        osc_calculate_location_slug('city');
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']."&region=".$regionId);
                break;
                case('edit_city'):      // edit city
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $mRegion = new Region();
                                        $mCities = new City();
                                        $newCity = Params::getParam('e_city');
                                        $cityId  = Params::getParam('city_id');

                                        if(!osc_validate_min($newCity, 1)) {
                                            osc_add_flash_error_message(_m('City name cannot be blank'), 'admin');
                                        } else {
                                            $exists = $mCities->findByName($newCity);
                                            if(!isset($exists['pk_i_id']) || $exists['pk_i_id']==$cityId) {
                                                $city = $mCities->findByPrimaryKey($cityId);
                                                $region = $mRegion->findByPrimaryKey($city['fk_i_region_id']);
                                                $country = Country::newInstance()->findByCode($region['fk_c_country_code']);

                                                $name = $newCity;
                                                $slug = Params::getParam('e_country_slug');
                                                if($slug=='') {
                                                    $slug_tmp = $slug = osc_sanitizeString($name);
                                                } else {
                                                    $exists = $mCities->findBySlug($slug);
                                                    if(isset($exists['s_slug']) && $exists['pk_i_id']!=$cityId) {
                                                        $slug_tmp = $slug = osc_sanitizeString($name);
                                                    } else {
                                                        $slug_tmp = $slug = osc_sanitizeString($slug);
                                                    }
                                                }
                                                $slug_unique = 1;
                                                while(true) {
                                                    $location_slug = $mCities->findBySlug($slug);
                                                    if(isset($location_slug['s_slug']) && $location_slug['pk_i_id']!=$cityId) {
                                                        $slug = $slug_tmp . '-' . $slug_unique;
                                                        $slug_unique++;
                                                    } else {
                                                        break;
                                                    }
                                                }

                                                $mCities->update(array('s_name' => $newCity, 's_slug' => $slug)
                                                                ,array('pk_i_id' => $cityId));
                                                ItemLocation::newInstance()->update(
                                                    array('s_city'       => $newCity),
                                                    array('fk_i_city_id' => $cityId)
                                                );
                                                osc_add_flash_ok_message(sprintf(_m('%s has been edited'), $newCity), 'admin');
                                            } else {
                                                osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newCity), 'admin');
                                            }
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']."&region=".@$region['pk_i_id']);
                break;
                case('delete_city'):    // delete city
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $mCities = new City();
                                        $cityIds  = Params::getParam('id');
                                        if(is_array($cityIds)) {
                                            $locations = 0;
                                            $del_locations = 0;
                                            $cCity = end($cityIds);
                                            $cCity = $mCities->findByPrimaryKey($cCity);
                                            $region = Region::newInstance()->findByPrimaryKey($cCity['fk_i_region_id']);
                                            $country = Country::newInstance()->findByCode($cCity['fk_c_country_code']);
                                            foreach($cityIds as $cityId) {
                                                $ok = $mCities->deleteByPrimaryKey($cityId);
                                                if($ok==0) {
                                                    $del_locations++;
                                                } else {
                                                    $locations += $ok;
                                                }
                                            }
                                            if($locations==0) {
                                                osc_add_flash_ok_message(sprintf(_n('One location has been deleted', '%d locations have been deleted', $del_locations), $del_locations), 'admin');
                                            } else {
                                                osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin');
                                            }
                                        } else {
                                            osc_add_flash_error_message(_m('No city was selected'), 'admin');
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']."&region=".@$region['pk_i_id']);
                break;
            }

            $aCountries = $mCountries->listAll();
            $this->_exportVariableToView('aCountries', $aCountries);

            $this->doView('settings/locations.php');
        }
Exemplo n.º 12
0
function osc_footer_link_url()
{
    $f = View::newInstance()->_get('footer_link');
    $url = osc_base_url();
    if (osc_get_preference('seo_url_search_prefix') != '') {
        $url .= osc_get_preference('seo_url_search_prefix') . '/';
    }
    $bCategory = false;
    if (osc_search_category_id()) {
        $bCategory = true;
        $cat = osc_get_category('id', $f['fk_i_category_id']);
        $url .= $cat['s_slug'] . '_';
    }
    if (osc_search_region() == '') {
        $url .= osc_sanitizeString($f['s_region']) . '-r' . $f['fk_i_region_id'];
    } else {
        $url .= osc_sanitizeString($f['s_city']) . '-c' . $f['fk_i_city_id'];
    }
    return $url;
}
Exemplo n.º 13
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'edit':
             if (Params::getParam("id") == '') {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             }
             $form = count(Session::newInstance()->_getForm());
             $keepForm = count(Session::newInstance()->_getKeepForm());
             if ($form == 0 || $form == $keepForm) {
                 Session::newInstance()->_dropKeepForm();
             }
             $templates = osc_apply_filter('page_templates', WebThemes::newInstance()->getAvailableTemplates());
             $this->_exportVariableToView('templates', $templates);
             $this->_exportVariableToView("page", $this->pageManager->findByPrimaryKey(Params::getParam("id")));
             $this->doView("pages/frm.php");
             break;
         case 'edit_post':
             osc_csrf_check();
             $id = Params::getParam("id");
             $b_link = Params::getParam("b_link") != '' ? 1 : 0;
             $s_internal_name = Params::getParam("s_internal_name");
             $s_internal_name = osc_sanitizeString($s_internal_name);
             $meta = Params::getParam('meta');
             $this->pageManager->updateMeta($id, json_encode($meta));
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray('', false);
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             Session::newInstance()->_setForm('aFieldsDescription', $aFieldsDescription);
             if ($s_internal_name == '') {
                 osc_add_flash_error_message(_m('You have to set an internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=edit&id=" . $id);
             }
             if (!WebThemes::newInstance()->isValidPage($s_internal_name)) {
                 osc_add_flash_error_message(_m('You have to set a different internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=edit&id=" . $id);
             }
             Session::newInstance()->_setForm('s_internal_name', $s_internal_name);
             if ($not_empty) {
                 foreach ($aFieldsDescription as $k => $_data) {
                     $this->pageManager->updateDescription($id, $k, $_data['s_title'], $_data['s_text']);
                 }
                 if (!$this->pageManager->internalNameExists($id, $s_internal_name)) {
                     if (!$this->pageManager->isIndelible($id)) {
                         $this->pageManager->updateInternalName($id, $s_internal_name);
                         $this->pageManager->updateLink($id, $b_link);
                     }
                     osc_run_hook('edit_page', $id);
                     Session::newInstance()->_clearVariables();
                     osc_add_flash_ok_message(_m('The page has been updated'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
                 }
                 osc_add_flash_error_message(_m("You can't repeat internal name"), 'admin');
             } else {
                 osc_add_flash_error_message(_m("The page couldn't be updated, at least one title should not be empty"), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=edit&id=" . $id);
             break;
         case 'add':
             $form = count(Session::newInstance()->_getForm());
             $keepForm = count(Session::newInstance()->_getKeepForm());
             if ($form == 0 || $form == $keepForm) {
                 Session::newInstance()->_dropKeepForm();
             }
             $templates = osc_apply_filter('page_templates', WebThemes::newInstance()->getAvailableTemplates());
             $this->_exportVariableToView('templates', $templates);
             $this->_exportVariableToView("page", array());
             $this->doView("pages/frm.php");
             break;
         case 'add_post':
             osc_csrf_check();
             $s_internal_name = Params::getParam("s_internal_name");
             $b_link = Params::getParam("b_link") != '' ? 1 : 0;
             $s_internal_name = osc_sanitizeString($s_internal_name);
             $meta = Params::getParam('meta');
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray('', false);
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             Session::newInstance()->_setForm('aFieldsDescription', $aFieldsDescription);
             if ($s_internal_name == '') {
                 osc_add_flash_error_message(_m('You have to set an internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             }
             if (!WebThemes::newInstance()->isValidPage($s_internal_name)) {
                 osc_add_flash_error_message(_m('You have to set a different internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             }
             $aFields = array('s_internal_name' => $s_internal_name, 'b_indelible' => '0', 's_meta' => json_encode($meta), 'b_link' => $b_link);
             Session::newInstance()->_setForm('s_internal_name', $s_internal_name);
             $page = $this->pageManager->findByInternalName($s_internal_name);
             if (!isset($page['pk_i_id'])) {
                 if ($not_empty) {
                     $result = $this->pageManager->insert($aFields, $aFieldsDescription);
                     Session::newInstance()->_clearVariables();
                     osc_add_flash_ok_message(_m('The page has been added'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
                 } else {
                     osc_add_flash_error_message(_m("The page couldn't be added, at least one title should not be empty"), 'admin');
                 }
             } else {
                 osc_add_flash_error_message(_m("Oops! That internal name is already in use. We can't make the changes"), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             break;
         case 'delete':
             osc_csrf_check();
             $id = Params::getParam("id");
             $page_deleted_correcty = 0;
             $page_deleted_error = 0;
             $page_indelible = 0;
             if (!is_array($id)) {
                 $id = array($id);
             }
             foreach ($id as $_id) {
                 $result = (int) $this->pageManager->deleteByPrimaryKey($_id);
                 switch ($result) {
                     case -1:
                         $page_indelible++;
                         break;
                     case 0:
                         $page_deleted_error++;
                         break;
                     case 1:
                         $page_deleted_correcty++;
                 }
             }
             if ($page_indelible > 0) {
                 if ($page_indelible == 1) {
                     osc_add_flash_error_message(_m("One page can't be deleted because it is indelible"), 'admin');
                 } else {
                     osc_add_flash_error_message(sprintf(_m("%s pages couldn't be deleted because they are indelible"), $page_indelible), 'admin');
                 }
             }
             if ($page_deleted_error > 0) {
                 if ($page_deleted_error == 1) {
                     osc_add_flash_error_message(_m("One page couldn't be deleted"), 'admin');
                 } else {
                     osc_add_flash_error_message(sprintf(_m("%s pages couldn't be deleted"), $page_deleted_error), 'admin');
                 }
             }
             if ($page_deleted_correcty > 0) {
                 if ($page_deleted_correcty == 1) {
                     osc_add_flash_ok_message(_m('One page has been deleted correctly'), 'admin');
                 } else {
                     osc_add_flash_ok_message(sprintf(_m('%s pages have been deleted correctly'), $page_deleted_correcty), 'admin');
                 }
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             break;
         default:
             if (Params::getParam("action") != "") {
                 osc_run_hook("page_bulk_" . Params::getParam("action"), Params::getParam('id'));
             }
             require_once osc_lib_path() . "osclass/classes/datatables/PagesDataTable.php";
             // set default iDisplayLength
             if (Params::getParam('iDisplayLength') != '') {
                 Cookie::newInstance()->push('listing_iDisplayLength', Params::getParam('iDisplayLength'));
                 Cookie::newInstance()->set();
             } else {
                 // set a default value if it's set in the cookie
                 $listing_iDisplayLength = (int) Cookie::newInstance()->get_value('listing_iDisplayLength');
                 if ($listing_iDisplayLength == 0) {
                     $listing_iDisplayLength = 10;
                 }
                 Params::setParam('iDisplayLength', $listing_iDisplayLength);
             }
             $this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength'));
             // Table header order by related
             if (Params::getParam('sort') == '') {
                 Params::setParam('sort', 'date');
             }
             if (Params::getParam('direction') == '') {
                 Params::setParam('direction', 'desc');
             }
             $page = (int) Params::getParam('iPage');
             if ($page == 0) {
                 $page = 1;
             }
             Params::setParam('iPage', $page);
             $params = Params::getParamsAsArray();
             $pagesDataTable = new PagesDataTable();
             $pagesDataTable->table($params);
             $aData = $pagesDataTable->getData();
             if (count($aData['aRows']) == 0 && $page != 1) {
                 $total = (int) $aData['iTotalDisplayRecords'];
                 $maxPage = ceil($total / (int) $aData['iDisplayLength']);
                 $url = osc_admin_base_url(true) . '?' . Params::getServerParam('QUERY_STRING', false, false);
                 if ($maxPage == 0) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=1', $url);
                     $this->redirectTo($url);
                 }
                 if ($page > 1) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=' . $maxPage, $url);
                     $this->redirectTo($url);
                 }
             }
             $this->_exportVariableToView('aData', $aData);
             $this->_exportVariableToView('aRawRows', $pagesDataTable->rawRows());
             $bulk_options = array(array('value' => '', 'data-dialog-content' => '', 'label' => __('Bulk actions')), array('value' => 'delete', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected pages?'), strtolower(__('Delete'))), 'label' => __('Delete')));
             $bulk_options = osc_apply_filter("page_bulk_filter", $bulk_options);
             $this->_exportVariableToView('bulk_options', $bulk_options);
             $this->doView("pages/index.php");
             break;
     }
 }
Exemplo n.º 14
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'edit':
             if (Params::getParam("id") == '') {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             }
             $form = count(Session::newInstance()->_getForm());
             $keepForm = count(Session::newInstance()->_getKeepForm());
             if ($form == 0 || $form == $keepForm) {
                 Session::newInstance()->_dropKeepForm();
             }
             $this->_exportVariableToView("page", $this->pageManager->findByPrimaryKey(Params::getParam("id")));
             $this->doView("pages/frm.php");
             break;
         case 'edit_post':
             $id = Params::getParam("id");
             $s_internal_name = Params::getParam("s_internal_name");
             $s_internal_name = osc_sanitizeString($s_internal_name);
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray('', false);
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             Session::newInstance()->_setForm('aFieldsDescription', $aFieldsDescription);
             if ($s_internal_name == '') {
                 osc_add_flash_error_message(_m('You have to set an internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=edit&id=" . $id);
             }
             if (!WebThemes::newInstance()->isValidPage($s_internal_name)) {
                 osc_add_flash_error_message(_m('You have to set a different internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=edit&id=" . $id);
             }
             Session::newInstance()->_setForm('s_internal_name', $s_internal_name);
             if ($not_empty) {
                 foreach ($aFieldsDescription as $k => $_data) {
                     $this->pageManager->updateDescription($id, $k, $_data['s_title'], $_data['s_text']);
                 }
                 if (!$this->pageManager->internalNameExists($id, $s_internal_name)) {
                     if (!$this->pageManager->isIndelible($id)) {
                         $this->pageManager->updateInternalName($id, $s_internal_name);
                     }
                     Session::newInstance()->_clearVariables();
                     osc_add_flash_ok_message(_m('The page has been updated'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
                 }
                 osc_add_flash_error_message(_m("You can't repeat internal name"), 'admin');
             } else {
                 osc_add_flash_error_message(_m("The page couldn't be updated, at least one title should not be empty"), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=edit&id=" . $id);
             break;
         case 'add':
             $form = count(Session::newInstance()->_getForm());
             $keepForm = count(Session::newInstance()->_getKeepForm());
             if ($form == 0 || $form == $keepForm) {
                 Session::newInstance()->_dropKeepForm();
             }
             $this->_exportVariableToView("page", array());
             $this->doView("pages/frm.php");
             break;
         case 'add_post':
             $s_internal_name = Params::getParam("s_internal_name");
             $s_internal_name = osc_sanitizeString($s_internal_name);
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray('', false);
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             Session::newInstance()->_setForm('aFieldsDescription', $aFieldsDescription);
             if ($s_internal_name == '') {
                 osc_add_flash_error_message(_m('You have to set an internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             }
             if (!WebThemes::newInstance()->isValidPage($s_internal_name)) {
                 osc_add_flash_error_message(_m('You have to set a different internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             }
             $aFields = array('s_internal_name' => $s_internal_name, 'b_indelible' => '0');
             Session::newInstance()->_setForm('s_internal_name', $s_internal_name);
             $page = $this->pageManager->findByInternalName($s_internal_name);
             if (!isset($page['pk_i_id'])) {
                 if ($not_empty) {
                     $result = $this->pageManager->insert($aFields, $aFieldsDescription);
                     Session::newInstance()->_clearVariables();
                     osc_add_flash_ok_message(_m('The page has been added'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
                 } else {
                     osc_add_flash_error_message(_m("The page couldn't be added, at least one title should not be empty"), 'admin');
                 }
             } else {
                 osc_add_flash_error_message(_m("Oops! That internal name is already in use. We can't make the changes"), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             break;
         case 'delete':
             $id = Params::getParam("id");
             $page_deleted_correcty = 0;
             $page_deleted_error = 0;
             $page_indelible = 0;
             if (!is_array($id)) {
                 $id = array($id);
             }
             foreach ($id as $_id) {
                 $result = (int) $this->pageManager->deleteByPrimaryKey($_id);
                 switch ($result) {
                     case -1:
                         $page_indelible++;
                         break;
                     case 0:
                         $page_deleted_error++;
                         break;
                     case 1:
                         $page_deleted_correcty++;
                 }
             }
             if ($page_indelible > 0) {
                 if ($page_indelible == 1) {
                     osc_add_flash_error_message(_m("One page can't be deleted because it is indelible"), 'admin');
                 } else {
                     osc_add_flash_error_message(sprintf(_m("%s pages couldn't be deleted because they are indelible"), $page_indelible), 'admin');
                 }
             }
             if ($page_deleted_error > 0) {
                 if ($page_deleted_error == 1) {
                     osc_add_flash_error_message(_m("One page couldn't be deleted"), 'admin');
                 } else {
                     osc_add_flash_error_message(sprintf(_m("%s pages couldn't be deleted"), $page_deleted_error), 'admin');
                 }
             }
             if ($page_deleted_correcty > 0) {
                 if ($page_deleted_correcty == 1) {
                     osc_add_flash_ok_message(_m('One page has been deleted correctly'), 'admin');
                 } else {
                     osc_add_flash_ok_message(sprintf(_m('%s pages have been deleted correctly'), $page_deleted_correcty), 'admin');
                 }
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             break;
         default:
             if (Params::getParam('iDisplayLength') == '') {
                 Params::setParam('iDisplayLength', 10);
             }
             $this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength'));
             require_once osc_admin_base_path() . 'ajax/pages_processing.php';
             $params = Params::getParamsAsArray('get');
             $pages_processing = new PagesProcessing($params);
             $aData = $pages_processing->result($params);
             $page = (int) Params::getParam('iPage');
             if (count($aData['aaData']) == 0 && $page != 1) {
                 $total = (int) $aData['iTotalDisplayRecords'];
                 $maxPage = ceil($total / (int) $aData['iDisplayLength']);
                 $url = osc_admin_base_url(true) . '?' . $_SERVER['QUERY_STRING'];
                 if ($maxPage == 0) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=1', $url);
                     $this->redirectTo($url);
                 }
                 if ($page > 1) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=' . $maxPage, $url);
                     $this->redirectTo($url);
                 }
             }
             $this->_exportVariableToView('aPages', $aData);
             $this->doView("pages/index.php");
             break;
     }
 }
Exemplo n.º 15
0
 public function install()
 {
     $this->import('payment/struct.sql');
     osc_set_preference('version', '200', 'payment', 'INTEGER');
     osc_set_preference('default_premium_cost', '1.0', 'payment', 'STRING');
     osc_set_preference('allow_premium', '0', 'payment', 'BOOLEAN');
     osc_set_preference('default_publish_cost', '1.0', 'payment', 'STRING');
     osc_set_preference('pay_per_post', '0', 'payment', 'BOOLEAN');
     osc_set_preference('premium_days', '7', 'payment', 'INTEGER');
     osc_set_preference('currency', 'USD', 'payment', 'STRING');
     osc_set_preference('pack_price_1', '', 'payment', 'STRING');
     osc_set_preference('pack_price_2', '', 'payment', 'STRING');
     osc_set_preference('pack_price_3', '', 'payment', 'STRING');
     osc_set_preference('paypal_api_username', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('paypal_api_password', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('paypal_api_signature', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('paypal_email', '', 'payment', 'STRING');
     osc_set_preference('paypal_standard', '1', 'payment', 'BOOLEAN');
     osc_set_preference('paypal_sandbox', '1', 'payment', 'BOOLEAN');
     osc_set_preference('paypal_enabled', '0', 'payment', 'BOOLEAN');
     osc_set_preference('blockchain_btc_address', '', 'payment', 'STRING');
     osc_set_preference('blockchain_enabled', '0', 'payment', 'BOOLEAN');
     osc_set_preference('braintree_merchant_id', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('braintree_public_key', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('braintree_private_key', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('braintree_encryption_key', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('braintree_sandbox', 'sandbox', 'payment', 'STRING');
     osc_set_preference('braintree_enabled', '0', 'payment', 'BOOLEAN');
     osc_set_preference('stripe_secret_key', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('stripe_public_key', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('stripe_secret_key_test', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('stripe_public_key_test', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('stripe_sandbox', 'sandbox', 'payment', 'STRING');
     osc_set_preference('stripe_enabled', '0', 'payment', 'BOOLEAN');
     osc_set_preference('coinjar_merchant_user', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('coinjar_merchant_password', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('coinjar_api_key', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('coinjar_sb_merchant_user', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('coinjar_sb_merchant_password', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('coinjar_sb_api_key', payment_crypt(''), 'payment', 'STRING');
     osc_set_preference('coinjar_merchant_reference', osc_sanitizeString(osc_page_title()), 'payment', 'STRING');
     osc_set_preference('coinjar_sandbox', 'sandbox', 'payment', 'STRING');
     osc_set_preference('coinjar_enabled', '0', 'payment', 'BOOLEAN');
     $this->dao->select('pk_i_id');
     $this->dao->from(DB_TABLE_PREFIX . 't_item');
     $result = $this->dao->get();
     if ($result) {
         $items = $result->result();
         $date = date("Y-m-d H:i:s");
         foreach ($items as $item) {
             $this->createItem($item['pk_i_id'], 1, $date);
         }
     }
     $description[osc_language()]['s_title'] = '{WEB_TITLE} - Publish option for your ad: {ITEM_TITLE}';
     $description[osc_language()]['s_text'] = '<p>Hi {CONTACT_NAME}!</p><p>We just published your item ({ITEM_TITLE}) on {WEB_TITLE}.</p><p>{START_PUBLISH_FEE}</p><p>In order to make your ad available to anyone on {WEB_TITLE}, you should complete the process and pay the publish fee. You could do that on the following link: {PUBLISH_LINK}</p><p>{END_PUBLISH_FEE}</p><p>{START_PREMIUM_FEE}</p><p>You could make your ad premium and make it to appear on top result of the searches made on {WEB_TITLE}. You could do that on the following link: {PREMIUM_LINK}</p><p>{END_PREMIUM_FEE}</p><p>This is an automatic email, if you already did that, please ignore this email.</p><p>Thanks</p>';
     $res = Page::newInstance()->insert(array('s_internal_name' => 'email_payment', 'b_indelible' => '1'), $description);
 }