Example #1
0
function f_getfromARow(&$aFields, $fieldSearched, $fieldSearchedValue, $getField = null, $mode = "")
{
    $nfield = 0;
    if (strpos($mode, "-friendly-") !== false) {
        $fieldSearchedValue = url_slug($fieldSearchedValue);
    }
    if (is_null($aFields)) {
        echo "<br>null aFields :";
        echo parse_backtrace(debug_backtrace());
        return "";
    }
    $existcol = get_param($mode, "existcol");
    foreach ($aFields as $key => $aField) {
        if (strpos($mode, "-debug-") !== false) {
            var_dump($aField);
        }
        $found = false;
        //echo parse_backtrace(debug_backtrace());
        if (array_key_exists($fieldSearched, $aField)) {
            $fieldValue = strpos($mode, "-friendly-") !== false ? url_slug($aField[$fieldSearched]) : $aField[$fieldSearched];
            if (strpos($mode, "-debug-") !== false) {
                echo "<br>{$nfield})  fieldValue:" . $fieldValue . " &nbsp;&nbsp;&nbsp;recup: " . $aField[$getField] . " ppp:" . $aField[0] . "<br>";
            }
            if (strpos($mode, "-trim-") !== false) {
                if ($fieldSearchedValue == $fieldValue) {
                    $found = true;
                }
            } else {
                if (trim($fieldSearchedValue) == trim($fieldValue)) {
                    $found = true;
                }
            }
        }
        if ($found && $existcol != "" && !array_key_exists($existcol, $aField)) {
            $found = false;
        }
        if ($found) {
            if (strpos($mode, "-debug-") !== false) {
                echo " ***encontrado.";
            }
            if ($getField === null) {
                return $aField;
            } elseif ($getField == -1) {
                return $key;
                //$nfield; // devuelva la fila donde está
            } else {
                if (array_key_exists($getField, $aField)) {
                    return $aField[$getField];
                } else {
                    return "";
                }
            }
        }
        $nfield++;
    }
    return "";
}
Example #2
0
function getDownloadImage($type, $file, $sottoCat, $nome_brand, $nome_colore, $id)
{
    /*$path = str_replace("index.php","",$_SERVER["SCRIPT_FILENAME"]);
      $import_location = $path.'media/catalog/';
      if (!file_exists($import_location)){
          mkdir($import_location, 0755);
      }
      $import_location = $path.'media/catalog/'.$type.'/';
      if (!file_exists($import_location)){
          mkdir($import_location, 0755);
      }*/
    $file_path = "";
    // estensione foto
    $ext = pathinfo($file, PATHINFO_EXTENSION);
    if (strtolower($ext) == "jpg") {
        // recupero il numero della foto
        $punto = strrpos($file, ".");
        $file_new = substr($file, 0, $punto);
        // il numero dell'immagine
        $numero_img = substr($file_new, strlen($file_new) - 1, 1);
        $nome_file = replace_accents(url_slug(strtolower($sottoCat))) . "_" . replace_accents(url_slug(strtolower($nome_brand))) . "_" . replace_accents(url_slug(strtolower($nome_colore))) . "_" . replace_accents(url_slug(strtolower($id))) . "-" . $numero_img . "." . $ext;
        $import_location = "../../var/images";
        $file_source = Mage::getStoreConfig('oscommerceimportconf/oscconfiguration/conf_imageurl', Mage::app()->getStore()) . $file;
        $file_target = $import_location . "/" . $nome_file;
        $file_source = str_replace(" ", "%20", $file_source);
        if ($file != '' and !file_exists($file_target)) {
            $rh = fopen($file_source, 'rb');
            $wh = fopen($file_target, 'wb');
            if ($rh === false || $wh === false) {
                // error reading or opening file
                $file_path = "";
            } else {
                while (!feof($rh)) {
                    if (fwrite($wh, fread($rh, 1024)) === FALSE) {
                        $file_path = $file_target;
                    }
                }
            }
            fclose($rh);
            fclose($wh);
        }
        if (file_exists($file_target)) {
            if ($type == 'category') {
                $file_path = $file;
            } else {
                $file_path = $file_target;
            }
        }
        $img = new Imagick($file_path);
        $img->setOption('jpeg:extent', '150kb');
        $img->writeImage($file_path);
    }
    return $file_path;
}
Example #3
0
 function insert_news($data_ar, $count_word = 10)
 {
     //принимает массив array('url','img','title','text','date') и минимальный размер текста(колличество шинглов/5) ;
     //        $data_ar['text'] = $this->clear_txt($data_ar['text']);
     $data_ar['title'] = $this->CI->db->escape_str(strip_tags($data_ar['title']));
     //        $data_ar['donor'] = $this->get_donor_url($data_ar['url']);
     $txtLenth = $this->txtLenth($data_ar['text']);
     if ($txtLenth < 600) {
         echo "error #1 small text <br />\n";
         return FALSE;
     }
     $donorObj = new donorMsn($data_ar['donor-data']);
     $donorId = $donorObj->getId();
     $data_ar['text'] = $this->change_img_in_txt($data_ar['text'], $data_ar['url']);
     //замена изображений в тексте
     $data_ar['img_name'] = $this->load_img($data_ar['img'], $data_ar['url'], $data_ar['title']);
     if ($data_ar['img_name']) {
         //            $this->resizeImg('medium');
         $this->resizeImg('small');
     }
     $data_ar['url_name'] = url_slug($data_ar['title'], array('transliterate' => true));
     $data_ar['title'] = html_entity_decode($data_ar['title'], ENT_QUOTES, 'UTF-8');
     $data_ar['text'] = html_entity_decode($data_ar['text'], ENT_QUOTES, 'UTF-8');
     //        $sql = "   INSERT INTO `article`
     //                    SET
     //                        `title`         = '{$data_ar['title']}',
     //                        `description`   = '".$this->CI->db->escape_str($data_ar['description'])."',
     //                        `text`          = '".$this->CI->db->escape_str($data_ar['text']) ."',
     //                        `cat_id`        = '{$data_ar['cat_id']}',
     //                        `main_img`      = '{$data_ar['img_name']}',
     //                        `date`          = '{$data_ar['date']}',
     //                        `url_name`      = '{$data_ar['url_name']}',
     //                        `scan_url_id`   = '{$data_ar['scan_url_id']}',
     //                        `donor_id`      = '{$donorId}',
     //                        `canonical`     = '{$data_ar['canonical']}'
     //                ";
     $sql2 = "  INSERT INTO `article` \r\n                    SET\r\n                        `title`         = ?, \r\n                        `description`   = ?,    \r\n                        `text`          = ?,\r\n                        `cat_id`        = '{$data_ar['cat_id']}',    \r\n                        `main_img`      = '{$data_ar['img_name']}',\r\n                        `date`          = '{$data_ar['date']}',\r\n                        `url_name`      = '{$data_ar['url_name']}',\r\n                        `scan_url_id`   = '{$data_ar['scan_url_id']}',\r\n                        `donor_id`      = '{$donorId}',\r\n                        `canonical`     = '{$data_ar['canonical']}'    \r\n                ";
     //        echo $sql;
     //        $this->CI->db->query($sql);
     $this->CI->db->query($sql2, array($data_ar['title'], $data_ar['description'], $data_ar['text']));
     $article_id = $this->CI->db->insert_id();
     echo 'ОК - Занесена новая новость ID# ' . $article_id . ' - ' . $data_ar['title'] . "<br />\n";
     return TRUE;
 }
Example #4
0
 function insert_news($data_ar, $count_word = 10)
 {
     //принимает массив array('url','img','title','text','date') и минимальный размер текста(колличество шинглов/5) ;
     $data_ar['text'] = $this->clear_txt($data_ar['text']);
     $data_ar['title'] = $this->CI->db->escape_str(strip_tags($data_ar['title']));
     $data_ar['donor'] = $this->get_donor_url($data_ar['url']);
     $this_hash_ar = $this->get_shingles_hash($data_ar['text']);
     if (count($this_hash_ar) < $count_word) {
         echo "error #1 small text <br />\n";
         return FALSE;
     }
     $like_hash_list = $this->get_like_news_hash($this_hash_ar, 20);
     if ($like_hash_list != false) {
         //сравнение хешей
         foreach ($like_hash_list as $news_id => $like_hash_ar) {
             if ($this->comparison_shingles_hash($this_hash_ar, $like_hash_ar, 50) == true) {
                 //если найденно совпадение текста
                 echo "error #2 clone text. CloneID-" . $news_id . ' ' . $data_ar['title'] . "<br />\n";
                 return FALSE;
             }
         }
     }
     $data_ar['text'] = $this->change_img_in_txt($data_ar['text'], $data_ar['url']);
     //замена изображений в тексте
     $data_ar['img_name'] = $this->load_img($data_ar['img'], $data_ar['url']);
     if ($data_ar['img_name']) {
         $this->resizeImg('medium');
         $this->resizeImg('small');
     }
     //        $data_ar['url_name'] = seoUrl($data_ar['title']);
     $data_ar['url_name'] = url_slug($data_ar['title'], array('transliterate' => true));
     $sql = "   INSERT INTO `article` \n                    SET\n                        `title`         = '{$data_ar['title']}', \n                        `text`          = '" . $this->CI->db->escape_str($data_ar['text']) . "',\n                        `cat_id`        = '{$data_ar['cat_id']}',    \n                        `main_img`      = '{$data_ar['img_name']}',\n                        `date`          = '{$data_ar['date']}',\n                        `url_name`      = '{$data_ar['url_name']}',\n                        `donor`         = '{$data_ar['donor']}',\n                        `scan_url_id`   = '{$data_ar['scan_url_id']}',\n                        `author_id`     = '0',\n                        `donor_id`      = '{$data_ar['donor_id']}'\n                ";
     $this->CI->db->query($sql);
     $article_id = $this->CI->db->insert_id();
     if ($article_id) {
         #ID is "0" becouse "INSERT DELAYED INTO"
         $this->CI->parser_m->add_shingles($this_hash_ar, $article_id);
     }
     echo 'ОК - Занесена новая новость ID# ' . $article_id . ' - ' . $data_ar['title'] . "<br />\n";
     return TRUE;
 }
 public function Contenido($id)
 {
     global $sql;
     $this->notNulls = array(self::ID);
     $this->data = new stdClass();
     $this->nuevo = false;
     $id = $sql->con->real_escape_string($id);
     $this->id = $id;
     $sql->readDB(self::TABLE, self::ID . "='" . strtolower($id) . "'");
     if (($res = $sql->fetchAssoc()) && is_array($res)) {
         $res['URL'] = url_slug($res['TITULO__CON']);
         if (empty($res['FOTOGRANCON'])) {
             $res['FOTOGRANCON'] = "NoDisponible.jpg";
         }
         $res['GALERIA_CON'] = trim($res['GALERIA_CON']);
         $res['GALERIA_CON'] = unserialize($res['GALERIA_CON']);
         if (is_array($res['GALERIA_CON'])) {
             $tmp = $res['GALERIA_CON'];
             $tmp = array_merge(array($res['FOTOGRANCON']), $res['GALERIA_CON']);
             $c = 0;
             $f = 0;
             foreach ($tmp as $image) {
                 $res['slider'][$f][] = $image;
                 $c++;
                 if ($c == 4) {
                     $c = 0;
                     $f++;
                 }
             }
         }
         $cur = $sql->readDB("CATEGORIA", "ID______CAT=" . $res["CATEGORICON"]);
         if ($cat = $cur->fetch_assoc()) {
             $res['REFERER'] = url_slug($cat["NOMBRE__CAT"]);
             $res["JAVASCRIPT"] = "<script>var guide = '" . $res["REFERER"] . "';</script>";
         }
         $this->data->data = $res;
     } else {
         $this->nuevo = true;
     }
     $logged = false;
 }
Example #6
0
 public function guardar($contenido_id = null)
 {
     $this->load->helper('file');
     $respuesta = new stdClass();
     if ($contenido_id) {
         $contenido = Doctrine::getTable('Contenido')->find($contenido_id);
     } else {
         $contenido = new Contenido();
     }
     $this->form_validation->set_rules('titulo', 'Título', 'trim|required');
     $this->form_validation->set_rules('contenido', 'Contenido', 'required');
     if ($this->form_validation->run() == TRUE) {
         try {
             $url = !$this->input->post('url') ? $this->input->post('titulo') : $this->input->post('url');
             $contenido->titulo = $this->input->post('titulo');
             $contenido->url = url_slug($url, array('transliterate' => true));
             $contenido->contenido = $this->input->post('contenido');
             $contenido->plantilla = $this->input->post('plantilla');
             $contenido->maestro = 1;
             $contenido->save();
             $contenido->generarVersion();
             $this->session->set_flashdata('message', 'Contenido ' . ($contenido_id ? 'actualizado' : 'creado') . ' exitosamente');
             $respuesta->validacion = TRUE;
             redirect('backend/contenidos/ver/' . $contenido->id);
         } catch (Exception $e) {
             $respuesta->validacion = FALSE;
             $respuesta->errores = "<p class='error'>" . $e . "</p>";
         }
     } else {
         $respuesta->validacion = FALSE;
         $respuesta->errores = validation_errors('<p class="error">', '</p>');
     }
     $data['plantillas'] = get_filenames('application/views/contenido/');
     $data['contenido'] = $contenido;
     $data['content'] = 'backend/contenidos/form';
     $data['title'] = 'Backend - Guardar contenido';
     $this->load->view('backend/template', $data);
 }
Example #7
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update()
 {
     require_once app_path() . '/includes/url-slug/url_slug.php';
     $input = \Request::all();
     if (isset($input['title']) && trim($input['title']) == '') {
         if (isset($input['name']) && trim($input['name']) != '') {
             $input['title'] = trim($input['name']);
         }
     }
     if (isset($input['keywords']) && trim($input['keywords']) == '') {
         if (isset($input['name']) && trim($input['name']) != '') {
             $input['keywords'] = trim($input['name']);
         }
     }
     if (isset($input['description']) && trim($input['description']) == '') {
         if (isset($input['short_text']) && trim($input['short_text']) != '') {
             $input['description'] = trim($input['short_text']);
         }
     }
     if ($input['id']) {
         if (isset($input['pseudo_url']) && trim($input['pseudo_url']) == '') {
             if (isset($input['name']) && trim($input['name']) != '') {
                 $input['pseudo_url'] = Content::checkURL(url_slug(trim($input['name']), array('transliterate' => true)), $input['id']);
             }
         } elseif (isset($input['pseudo_url']) && trim($input['pseudo_url']) != '') {
             $input['pseudo_url'] = Content::checkURL(url_slug(trim($input['pseudo_url']), array('transliterate' => true)), $input['id']);
         }
         Content::find($input['id'])->update($input);
     } else {
         if (isset($input['pseudo_url']) && trim($input['pseudo_url']) == '') {
             if (isset($input['name']) && trim($input['name']) != '') {
                 $input['pseudo_url'] = Content::checkURL(url_slug(trim($input['name']), array('transliterate' => true)), null);
             }
         } elseif (isset($input['pseudo_url']) && trim($input['pseudo_url']) != '') {
             $input['pseudo_url'] = Content::checkURL(url_slug(trim($input['pseudo_url']), array('transliterate' => true)), null);
         }
         $input = Content::create($input);
     }
     if (\Input::file() && isset($input['id'])) {
         if (\Input::file('image') && \Input::file('image')->isValid()) {
             if (in_array(\Input::file('image')->getClientOriginalExtension(), ['jpg', 'jpeg', 'png'])) {
                 $destinationPath = 'images/content/' . $input['id'];
                 $extension = \Input::file('image')->getClientOriginalExtension();
                 $fileName = 'preview' . '.' . $extension;
                 \Input::file('image')->move($destinationPath, $fileName);
             }
         }
     }
     return \Redirect::action('Admin\\ContentController@show', ['id' => $input['id'], $input['tab'], 'type' => $input['type']]);
 }
Example #8
0
 public function upload()
 {
     $this->load->library('form_validation');
     $this->load->model('Video_model');
     $this->output->set_header('Content-Type: application/json; charset=utf-8');
     $user = $this->ion_auth->user()->row();
     $this->form_validation->set_rules('title', 'Video Title', 'trim|required|min_length[2]|max_length[255]|xss_clean');
     $this->form_validation->set_rules('url', 'Video URL', 'trim|required|min_length[2]|max_length[255]|xss_clean');
     $this->form_validation->set_rules('description', 'Description', 'trim|min_length[2]|max_length[500]|xss_clean');
     $title = $this->input->post('title', TRUE);
     $url = $this->input->post('url', TRUE);
     $description = $this->input->post('description', TRUE);
     $video_id = 0;
     $video_source = 0;
     if ($this->form_validation->run() === FALSE) {
         //validation errors
         $output_array = array('validation' => 'error', 'message' => validation_errors('<div class="alert alert-error"><strong>Error!</strong> ', '</div>'));
         $this->output->set_output(json_encode($output_array));
     } else {
         $vimeo = json_decode($this->vimeoCurl($url));
         if (isset($vimeo->video_id)) {
             $video_id = $vimeo->video_id;
             $video_source = 'vimeo';
             $video_img = $vimeo->thumbnail_url;
         } elseif (preg_match('/^(?:https?:\\/\\/)?(?:www\\.)?youtube\\.com\\/watch\\?(?=.*v=((\\w|-){11}))(?:\\S+)?$/', $url)) {
             parse_str(parse_url($url, PHP_URL_QUERY), $my_array_of_vars);
             if (!empty($my_array_of_vars['v'])) {
                 $video_id = $my_array_of_vars['v'];
                 $video_source = 'youtube';
                 $video_img = 'http://img.youtube.com/vi/' . $video_id . '/hqdefault.jpg';
             }
         }
         if ($video_id === 0 || $video_source === 0) {
             $output_array = array('validation' => 'valid', 'response' => 'error', 'message' => '<div class="alert alert-error">Video Source Not Supported. Only Vimeo and Youtube Links are supported.<br />Ensure there is an http:// or https:// in front of the URL string.</div>');
             $this->output->set_output(json_encode($output_array));
         } else {
             $this->load->library('images');
             // Make sure the fileName is unique
             if (file_exists(FCPATH . 'asset_uploads/' . $user->username . '/videos/' . url_slug($title) . '.jpg')) {
                 $fileName = url_slug($title) . '_1';
             } else {
                 $fileName = url_slug($title);
             }
             $data = array('user_id' => $user->id, 'video_title' => $title, 'video_description' => $description, 'video_source' => $video_source, 'video_id' => $video_id, 'video_url' => url_slug($title), 'video_img' => $fileName . '.jpg', 'upload_date' => time());
             $resizeDir = FCPATH . 'asset_uploads/' . $user->username . '/videos/';
             $this->images->uploadRemoteFile($video_img, $fileName, 'videos', $user->id);
             $this->images->resizeImage($resizeDir, $fileName, 'jpg', '150');
             $upload = $this->Video_model->add_video($data);
             if (!$upload) {
                 $output_array = array('validation' => 'valid', 'response' => 'error', 'message' => 'Unable to submit. Please try again');
                 $this->output->set_output(json_encode($output_array));
             } else {
                 $output_array = array('validation' => 'valid', 'response' => 'success', 'message' => 'Your video has been submitted but is not yet active (pending approval).<br />If approved, your video will be available <a href="' . base_url('videos/' . $user->username . '/' . url_slug($title)) . '">HERE</a>.');
                 $this->output->set_output(json_encode($output_array));
             }
         }
     }
     //validation
 }
Example #9
0
 function getLoadImgFname($mimeType, $alt = '')
 {
     if (!empty($alt)) {
         $newAlt = url_slug($alt, array('transliterate' => true));
         $newAlt = $newAlt . '_';
         $newAlt = mb_substr($newAlt, 0, 100);
         $newAlt = preg_replace("#_[^_]+#i", '', $newAlt);
         //удаление обрезанного слова
         $imgName = $newAlt . '_' . mt_rand(100, 999999) . '_' . $this->getImgExtensionFromMType($mimeType);
     } else {
         $imgName = md5(mt_rand(100, 999999) . '_' . time()) . '_' . $this->getImgExtensionFromMType($mimeType);
     }
     return $imgName;
 }
 public function edit_echipa($cat, $id, $del_photo = null)
 {
     if ($del_photo) {
         $photo = $this->mysql->get_row('echipa', array('id_echipa' => $id));
         if ($photo['photo'] != '' and file_exists($_SERVER['DOCUMENT_ROOT'] . $photo['photo'])) {
             unlink($_SERVER['DOCUMENT_ROOT'] . $photo['photo']);
         }
     }
     if ($id) {
         $i = 0;
         foreach ($cat as $item) {
             if ($this->mysql->update('echipa', $item, array('id_echipa' => $id))) {
                 $this->session->set_flashdata('succes', lang('edit_succes'));
             } else {
                 $this->session->set_flashdata('erorr', lang('edit_erorr'));
             }
         }
         //add log
         $this->mysql->logs('edit', 'A editat un membru de echipa', 'admin/echipa_form/0/' . $id);
     } else {
         $this->session->set_flashdata('erorr', lang('id_erorr'));
     }
     $ord = $this->mysql->get_row('echipa', array('id_echipa' => $id));
     //url
     $echipa = $this->mysql->get_row('echipa', array('id_echipa' => $id));
     $url = url_slug($echipa['name_ro']);
     $url_exists = $this->mysql->get_row('echipa', array('url' => $url, 'id_echipa !=' => $id));
     if ($url_exists) {
         $url = $url . '_' . $id;
     }
     $this->mysql->update('echipa', array('url' => $url), array('id_echipa' => $id));
     //end url
     if ($ord['ord'] == 0) {
         $this->mysql->update('echipa', array('ord' => $id), array('id_echipa' => $id));
     }
 }
Example #11
0
header('Content-type: text/plain; charset=utf-8');
// Basic usage
echo "This is an example string. Nothing fancy." . "\n";
echo url_slug("This is an example string. Nothing fancy.") . "\n\n";
// Example using French with unwanted characters ('?)
echo "Qu'en est-il français? Ça marche alors?" . "\n";
echo url_slug("Qu'en est-il français? Ça marche alors?") . "\n\n";
// Example using transliteration
echo "Что делать, если я не хочу, UTF-8?" . "\n";
echo url_slug("Что делать, если я не хочу, UTF-8?", array('transliterate' => true)) . "\n\n";
// Example using transliteration on an unsupported language
echo "מה אם אני לא רוצה UTF-8 תווים?" . "\n";
echo url_slug("מה אם אני לא רוצה UTF-8 תווים?", array('transliterate' => true)) . "\n\n";
// Some other options
echo "This is an Example String. What's Going to Happen to Me?" . "\n";
echo url_slug("This is an Example String. What's Going to Happen to Me?", array('delimiter' => '_', 'limit' => 40, 'lowercase' => false, 'replacements' => array('/\\b(an)\\b/i' => 'a', '/\\b(example)\\b/i' => 'Test')));
/*
Output:

This is an example string. Nothing fancy.
this-is-an-example-string-nothing-fancy

Qu'en est-il français? Ça marche alors?
qu-en-est-il-français-ça-marche-alors

Что делать, если я не хочу, UTF-8?
chto-delat-esli-ya-ne-hochu-utf-8

מה אם אני לא רוצה UTF-8 תווים?
מה-אם-אני-לא-רוצה-utf-8-תווים
include_once "HTML/Template/Flexy.php";
$tpl = new stdClass();
$config = new Configuracion($sql);
$error = true;
$cursor = $sql->readDB("CONTENIDO", "ESTADO__CON='A'");
while ($row = $cursor->fetch_assoc()) {
    if (url_slug($row['TITULO__CON']) == substr($_SERVER['REQUEST_URI'], 1)) {
        $error = false;
    }
    if ("contenido=" . $row["ID______CON"] == substr($_SERVER['REQUEST_URI'], 1)) {
        $error = false;
    }
}
$cursor = $sql->readDB("CATEGORIA");
while ($row = $cursor->fetch_assoc()) {
    if (url_slug($row['NOMBRE__CAT']) == substr($_SERVER['REQUEST_URI'], 1)) {
        $error = false;
    }
}
if (!$error) {
    Header("HTTP/1.0 200 OK");
    $_REQUEST['bufferedHTML'] = true;
    $_REQUEST['what'] = substr($_SERVER['REQUEST_URI'], 1);
    include_once "getContent.php";
    $content = $retval['html'];
    $content .= "<script>var error = true; var passedURL = '" . substr($_SERVER['REQUEST_URI'], 1) . "';</script>";
    include_once "container.php";
    exit;
}
$options = array('templateDir' => $install . "/template", 'compileDir' => $install . "/tmp");
$object = new HTML_Template_Flexy($options);
Example #13
0
    $tpl->PREV = true;
}
if ($actual < $total) {
    $tpl->NEXT = true;
}
$tpl->TOTAL = $total;
$tpl->ACTUAL = $actual;
$cursor = $sql->readDB("CONTENIDO,CATEGORIA", "ESTADO__CON='A' AND ID______CAT=CATEGORICON", null, "*", ($actual - 1) * $porpagina . "," . $porpagina);
if ($cursor && $cursor->num_rows > 0) {
    while ($row = $cursor->fetch_assoc()) {
        $group = $row['ID______CAT'];
        $key = $row['ID______CON'];
        //$cont = new Contenido($row['ID______CON']);
        $row['FECHA___CON'] = date('d/m/Y H:i', strtotime($row['FECHA___CON']));
        $tpl->CONTENIDO[$group][$key] = $row;
        //$cont->getHTML();
    }
}
$tpl->CONFIGURACION = array();
$cursor = $sql->readDB("CONFIGURACION");
if ($cursor->num_rows > 0) {
    while ($row = $cursor->fetch_assoc()) {
        $key = url_slug($row['NOMBRE__CFG']);
        $tpl->CONFIGURACION[$key] = $row['VALOR___CFG'];
    }
}
$options = array('templateDir' => 'templates', 'compileDir' => 'tmp');
$output = new HTML_Template_Flexy($options);
$output->compile('news.html');
$tpl->CONTENT = $output->bufferedOutputObject($tpl);
include "container.php";
$urlsPriority = array();
$base = "http://" . $_SERVER['HTTP_HOST'];
$urls = array();
$urlsPriority[] = $base;
$cursor = $sql->readDB("CATEGORIA", "ESTADO__CAT='A'");
while ($row = $cursor->fetch_assoc()) {
    $url = url_slug($row['NOMBRE__CAT']);
    if ($row['PADRE___CAT'] == '-1') {
        $urlsPriority[] = $base . "/" . $url;
    } else {
        $urls[] = $base . "/" . $url;
    }
}
if ($cursor = $sql->readDB("CONTENIDO", "ESTADO__CON='A'")) {
    while ($row = $cursor->fetch_assoc()) {
        if (!empty($row['TITULO__CON'])) {
            $url = url_slug($row['TITULO__CON']);
        } else {
            $url = "contenido=" . $row["ID______CON"];
        }
        $urls[] = $base . "/" . $url;
    }
}
$tpl->PRIORITY = $urlsPriority;
$tpl->URLS = $urls;
$tpl->DATE = date(DATE_ATOM);
//*
$output = new HTML_Template_Flexy(array('templateDir' => $install . "/template", 'compileDir' => $install . '/tmp'));
$output->compile("sitemap.xml");
$output->outputObject($tpl);
//*/
Example #15
0
 public function edit_catalog($cat, $id, $del_photo = null, $preturi = null, $preturi_red = null)
 {
     if ($del_photo) {
         $photo = $this->mysql->get_row('catalog', array('id' => $id));
         if ($photo['photo'] != '' and file_exists($_SERVER['DOCUMENT_ROOT'] . $photo['photo'])) {
             unlink($_SERVER['DOCUMENT_ROOT'] . $photo['photo']);
         }
         $this->mysql->update('catalog', array('photo_ro' => ''), array('id' => $id));
     }
     if ($id) {
         $i = 0;
         foreach ($cat as $item) {
             $i++;
             if ($this->mysql->update('catalog', $item, array('id' => $id))) {
                 $this->session->set_flashdata('succes', lang('edit_succes'));
             } else {
                 $this->session->set_flashdata('erorr', lang('edit_erorr'));
             }
         }
         /*echo '<pre>';
           print_r($_POST);*/
         //         foreach ($preturi as $key => $pret) {
         //            $ex_key = explode('_', $key);
         //            $pret_id = $this->mysql->update('preturi',array('pret'=>$pret),  array('product_id'=>$id,'model_id'=>$ex_key[1]));
         //            if ($this->mysql->get_row('preturi',array('model_id'=>$ex_key[1],'product_id'=>$id))==false) {
         //            $this->mysql->insert('preturi',array('pret'=>$pret,'product_id'=>$id,'model_id'=>$ex_key[1],'lungime_id'=>$ex_key[0]));
         //            }
         //        }
         //
         //        foreach ($preturi_red as $key => $pret) {
         //            $ex_key = explode('_', $key);
         //            $pret_id = $this->mysql->update('preturi',array('pret_red'=>$pret),  array('product_id'=>$id,'model_id'=>$ex_key[1]));
         //            if ($this->mysql->get_row('preturi',array('model_id'=>$ex_key[1],'product_id'=>$id))==false) {
         //            $this->mysql->insert('preturi',array('pret_red'=>$pret,'product_id'=>$id,'model_id'=>$ex_key[1],'lungime_id'=>$ex_key[0]));
         //            }
         //        }
     } else {
         $this->session->set_flashdata('erorr', lang('id_erorr'));
     }
     // ord
     $ord = $this->mysql->get_row('catalog', array('id' => $id));
     if ($ord['ord'] == 0) {
         $this->mysql->update('catalog', array('ord' => $id), array('id' => $id));
     }
     // url
     $catalog = $this->mysql->get_row('catalog', array('id' => $id));
     $url = url_slug($catalog['name_ro'], array('transliterate' => true, 'delimiter' => '-', 'lowercase' => true));
     $url_exists = $this->mysql->get_row('catalog', array('url' => $url, 'id !=' => $id));
     if ($url_exists) {
         $url = $url . '-' . $id;
     }
     $this->mysql->update('catalog', array('url' => $url), array('id' => $id));
     // end url
 }
<ul class="thumbnails">
	<?php 
foreach ($thumbs_small_gallery as $thumb) {
    ?>
		<li class="span2 thumbnail-small">
			<div class="thumbnail thumbnail-browse">
				<a href="<?php 
    echo '/gallery/view/' . $thumb['id'] . '/1/' . url_slug($thumb['name'], array('transliterate' => TRUE));
    ?>
">
				<div class="container-thumb-gallery">
					<?php 
    if (isset($thumb['gallery_thumb_images'][1])) {
        ?>
						<div class="left-top-thumb-gallery">
							<?php 
        echo img($thumb['gallery_thumb_images'][1]['plus_18'] && !$adult_user && !(isset($logged_in_user) && $logged_in_user->id === $thumb['owner']) ? array('src' => 'assets/img/stop_mini.png') : array('src' => $thumb_mini_config['path'] . $thumb['gallery_thumb_images'][1]['file_name']));
        ?>
						</div>
					<?php 
    }
    ?>
					<?php 
    if (isset($thumb['gallery_thumb_images'][3])) {
        ?>
						<div class="right-top-thumb-gallery">
							<?php 
        echo img($thumb['gallery_thumb_images'][3]['plus_18'] && !$adult_user && !(isset($logged_in_user) && $logged_in_user->id === $thumb['owner']) ? array('src' => 'assets/img/stop_mini.png') : array('src' => $thumb_mini_config['path'] . $thumb['gallery_thumb_images'][3]['file_name']));
        ?>
						</div>
					<?php 
        if ($_FILES["myfile"]["error"] > 0) {
            //echo "Error: " . $_FILES["file"]["error"] . "<br>";
        } else {
            $today = date("YmdHis");
            // 20010310
            //move the uploaded file to uploads folder;
            move_uploaded_file($_FILES["myfile"]["tmp_name"], $directory . $today . $_FILES["myfile"]["name"]);
            $image = $_FILES["myfile"]["name"];
            resize_image($directory, $today . $image);
        }
    }
    $id_publicacion = $_POST['id_publicacion'];
    $publicacion->setIdPublicacion($id_publicacion);
    $publicacion->setTitulo($_POST['titulo']);
    $url = $_POST['titulo'];
    $url = url_slug($url);
    // convertimos el titulo a URL para el blog
    $url = dropAccents($url);
    // quitamos acentos
    $publicacion->setURL($url);
    $publicacion->setTexto($_POST['texto']);
    $publicacion->setImagen($today . $image);
    $publicacion->updatePublicacion();
    header('Location: index.php');
}
?>
<!doctype html>
<html class="no-js" lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 public function edit_users($data, $id)
 {
     if ($id) {
         if (isset($data['last_name']) || isset($data['first_name'])) {
             $url = url_slug($data['first_name'] . ' ' . $data['last_name']);
             $url_exists = $this->mysql->get_row('auth_user', array('url' => $url, 'id !=' => $id));
             if ($url_exists) {
                 $url = $url . '_' . $id;
             }
             $data['url'] = $url;
             // end url
         }
         if ($this->mysql->update('auth_user', $data, array('id' => $id))) {
             $this->session->set_flashdata('succes', lang('edit_succes'));
             $this->mysql->logs('edit', 'A editat profilul ', 'admin/users_form/' . $id);
         } else {
             $this->session->set_flashdata('error', lang('edit_error'));
         }
     } else {
         $this->session->set_flashdata('error', lang('id_error'));
     }
 }
} else {
    ?>
			<li class="previous disabled">
				<?php 
    echo anchor("#", '&larr; poprzednia', array('onclick' => 'return false;'));
    ?>
			</li>							
		<?php 
}
?>
		<?php 
if (isset($next_image_id_name)) {
    ?>
			<li class="next">
				<?php 
    echo anchor("image/zoom/{$next_image_id_name->id}" . '/' . url_slug($next_image_id_name->title, array('transliterate' => TRUE)), 'następna &rarr;', array());
    ?>
			</li>				
		<?php 
} else {
    ?>
			<li class="next disabled">
				<?php 
    echo anchor("#", 'następna &rarr;', array('onclick' => 'return false;'));
    ?>
			</li>				
		<?php 
}
?>
	
	</ul>
Example #20
0
 function insert_news($data_ar, $count_word = 80, $rewrite_news = true)
 {
     //принимает массив array('url','img','title','text','date') и минимальный размер текста(колличество слов более 4 букв) ;
     $data_ar['text'] = $this->clear_txt($data_ar['text']);
     $data_ar['title'] = $this->db->escape_str(strip_tags($data_ar['title']));
     $data_ar['donor'] = $this->get_donor_url($data_ar['url']);
     $this_hash_ar = $this->get_shingles_hash($data_ar['text']);
     if (count($this_hash_ar) < $count_word) {
         echo "error #1 small text \n";
         return FALSE;
     }
     $like_hash_list = $this->get_like_news_hash($this_hash_ar);
     if ($like_hash_list != false) {
         //сравнение хешей
         foreach ($like_hash_list as $news_id => $like_hash_ar) {
             if ($this->comparison_shingles_hash($this_hash_ar, $like_hash_ar, 60) == true) {
                 //если найденно совпадение текста
                 if (count($this_hash_ar) > count($like_hash_ar) && $rewrite_news == true) {
                     //если новый текст больше старого, то перезапись старого текста новым
                     $data_ar['text'] = $this->change_img_in_txt($data_ar['text'], $data_ar['url']);
                     //замена изображений в тексте
                     $this->CI->db->query("  UPDATE `articles` \n                                                SET \n                                                    `title`         = '{$data_ar['title']}', \n                                                    `text`          = '" . $this->db->escape_str($data_ar['text']) . "',\n                                                    `donor_url`     = '{$data_ar['url']}',\n                                                    `donor_host`    = '{$data_ar['donor']}',    \n                                                    `shingles_hash` = '" . serialize($this_hash_ar) . "' \n                                                WHERE `id`='{$news_id}' \n                                             ");
                     echo 'ОК - Запись перезаписана ID-' . $news_id . ' - ' . $data_ar['title'] . "\n";
                 }
                 echo "error #2 clone text. CloneID-" . $news_id . ' ' . $data_ar['title'] . "\n";
                 return FALSE;
             }
         }
     }
     $data_ar['text'] = $this->change_img_in_txt($data_ar['text'], $data_ar['url']);
     //замена изображений в тексте
     $data_ar['img_name'] = $this->load_img($data_ar['img'], $data_ar['url']);
     //         $data_ar['url_name']    = seoUrl( $data_ar['title'] );
     $data_ar['url_name'] = url_slug($data_ar['title'], array('transliterate' => true));
     $this->CI->db->query("  INSERT INTO `articles` \n                                 SET\n                                    `title`         = '{$data_ar['title']}', \n                                    `text`          = '" . $this->db->escape_str($data_ar['text']) . "',\n                                    `img`           = '{$data_ar['img_name']}',\n                                    `date`          = '{$data_ar['date']}',\n                                    `url_name`      = '{$data_ar['url_name']}',\n                                    `donor_url`     = '{$data_ar['url']}',\n                                    `donor_host`    = '{$data_ar['donor']}',    \n                                    `shingles_hash` = '" . serialize($this_hash_ar) . "'  \n                               ");
     echo 'ОК - Занесена новая новость ID# ' . $this->CI->db->insert_id() . ' - ' . $data_ar['title'] . "\n";
     return TRUE;
 }
<ul class="thumbnails">
	<?php 
foreach ($thumbs_mini as $thumb) {
    ?>
		<li class="span1 thumbnail-mini">
			<div class="thumbnail">
				<a href="<?php 
    echo '/image/preview/' . $thumb['imgs_id'] . '/' . url_slug($thumb['title'], array('transliterate' => TRUE));
    ?>
" alt="<?php 
    echo $thumb['title'];
    ?>
">
				<div class="container-thumb-mini">
					<div class="outer-block-thumb-mini">
						<?php 
    echo img($thumb['plus_18'] && !$adult_user && !(isset($logged_in_user) && $logged_in_user->id === $thumb['owner']) ? array('src' => 'assets/img/stop_mini.png') : array('src' => $thumb_mini_config['path'] . $thumb['file_name']));
    ?>
					</div>
				</div>
				</a>
			</div>
		</li>
	<?php 
}
?>
</ul>
Example #22
0
 public function add_category()
 {
     //ajax add post function used in conjunction with create_post
     if (!$this->ion_auth->is_admin()) {
         redirect('errors/page_missing', 'refresh');
     }
     $this->output->set_header('Content-Type: application/json; charset=utf-8');
     $this->load->library('form_validation');
     $this->form_validation->set_rules('new_category', 'Category Name', 'trim|required|min_length[2]|max_length[255]|xss_clean');
     $new_category = url_slug($this->input->post('new_category'));
     //check if there is an existing post
     $existing = $this->Blog_model->get_category(array('title' => $new_category));
     if ($existing) {
         $output = array('validation' => 'error', 'response' => 'error', 'message' => 'Category already exists.');
     } else {
         if ($this->form_validation->run() == FALSE) {
             $output = array('validation' => 'error', 'message' => validation_errors());
         } else {
             $add = $this->Blog_model->add_category(array('title' => $new_category));
             if ($add) {
                 $output = array('validation' => 'valid', 'response' => 'success', 'message' => 'Category Added');
             } else {
                 $output = array('validation' => 'valid', 'response' => 'error', 'message' => 'Category already exists');
             }
             //if add
         }
         // if validation
     }
     // if existing category
     $this->output->set_output(json_encode($output));
 }
Example #23
0
 function _change_title_in_pda()
 {
     set_time_limit(300);
     $this->load->helper('parser/download');
     $this->load->helper('parser/simple_html_dom');
     $this->load->helper('parser/url_name2');
     $this->load->library('parser/Parse_page_lib');
     $this->load->library('parser/Parse_lib');
     $this->load->library('parser/Video_replace_lib');
     $sql = "SELECT `article`.`id`, `article`.`donor`, `scan_url`.`url` " . "FROM `article` " . "LEFT JOIN `scan_url` ON `article`.`scan_url_id` = `scan_url`.`id` " . "WHERE " . "`article`.`donor` = '4pda.ru' " . "AND " . "`article`.`title` = '' " . "LIMIT 50";
     $query = $this->db->query($sql);
     foreach ($query->result_array() as $row) {
         echo $row['id'] . ' - ' . $row['donor'] . ' - ' . $row['url'] . "<br />\n";
         $html = down_with_curl($row['url']);
         $data = $this->parse_page_lib->get_data($html, array('host' => $row['donor']));
         $title = $data['title'];
         $urlName = url_slug($title, array('transliterate' => true));
         $this->db->query("UPDATE `article` SET `title`='{$title}', `url_name`='{$urlName}' WHERE `id`='{$row['id']}' LIMIT 1 ");
         sleep(3);
     }
 }
} else {
    ?>
				<li class="previous disabled">
					<?php 
    echo anchor("#", '&larr; poprzednia', array('onclick' => 'return false;'));
    ?>
				</li>							
			<?php 
}
?>
			<?php 
if (isset($next_image_index)) {
    ?>
				<li class="next">
					<?php 
    echo anchor("gallery/view/{$gallery->id}/{$next_image_index}" . '/' . url_slug($gallery->name, array('transliterate' => TRUE)), 'następna &rarr;', array());
    ?>
				</li>				
			<?php 
} else {
    ?>
				<li class="next disabled">
					<?php 
    echo anchor("#", 'następna &rarr;', array('onclick' => 'return false;'));
    ?>
				</li>				
			<?php 
}
?>
	
		</ul>
Example #25
0
 function send_information_sms($data, $res_code)
 {
     $hotel_name = url_slug($data['hotel_info']->name);
     $res_code = $data['reservation_code'];
     $pincode = $data['pincode'];
     $from = $data['checkin'];
     $to = $data['checkout'];
     $price = $data['total_price'];
     $currency = $data['hotel_info']->currency;
     $msj = $hotel_name . "\n" . "Reservation Code:" . $res_code . "\n" . "Pincode:" . $pincode . "\n" . "From:" . $from . "\n" . "To:" . $to . "\n" . "Total:" . $price . $currency . "\n";
     $msj = urlencode($msj);
     $user = "******";
     $password = "******";
     $api_id = "3545801";
     $baseurl = "http://api.clickatell.com";
     //$text = urlencode("This is an example message");
     $text = $msj;
     //$to = "00123456789";
     $to = $data['mobile'];
     // auth call
     $url = "{$baseurl}/http/auth?user={$user}&password={$password}&api_id={$api_id}";
     // do auth call
     $ret = file($url);
     // explode our response. return string is on first line of the data returned
     $sess = explode(":", $ret[0]);
     if ($sess[0] == "OK") {
         $sess_id = trim($sess[1]);
         // remove any whitespace
         $url = "{$baseurl}/http/sendmsg?session_id={$sess_id}&to={$to}&text={$text}";
         // do sendmsg call
         $ret = file($url);
         $send = explode(":", $ret[0]);
         if ($send[0] == "ID") {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
require_once 'twitteroauth/twitteroauth.php';
require_once 'config.php';
require_once 'classes.php';
require_once 'url_slug.php';
$money_class = new MoneyStuff();
$user_class = new Users();
$various_class = new FunctionsAndVarious();
//var_dump($_POST);
$foto = $_FILES['campaign_imagen'];
$image_name = $various_class->UploadImage($foto);
if ($image_name != '') {
    $img_to_insert = UPLOAD_PATH . '/' . $image_name;
} else {
    $img_to_insert = '';
}
$name = $_POST['campaign_name'];
$friendly_url = url_slug($name);
$desc = $_POST['campaign_desc'];
$needed_money = $_POST['campaign_money_needed'];
$max_money = $_POST['campaign_money_max'];
$currency = $_SESSION['user_profile']['currency'];
$video_url = $_POST['campaign_utube_url'];
$campaign_type = $_POST['campaign_type'];
$user_id = $_SESSION['user_profile']['id'];
$save_campaign = $money_class->SaveNewCampaign($user_id, $name, $desc, $needed_money, $max_money, $currency, $img_to_insert, $video_url, $campaign_type, $friendly_url);
if ($save_campaign == true) {
    //print($save_campaign);
    printf("<script>document.location.href='campaign.php?id=" . $save_campaign . "'</script>;");
} else {
    print "FAILED";
}
    echo img(array('src' => 'assets/img/stop_preview.png', 'alt' => $preview_image->title, 'class' => "stop18"));
    ?>
						<div class="alert alert-block alert-error fade in alert-stop18">
							<button type="button" class="close" data-dismiss="alert">×</button>
							<h4 class="alert-heading">Niestety nie możesz zobaczyć tej pracy!</h4>
							<p>Praca może być przeglądana wyłącznie przez osoby pełnoletnie. <br />Aby ją zobaczyć musisz potwierdzić, że masz skończone 18 lat.</p>
							<p>
								<a href="#stop18-confirm-modal" role="button" data-toggle="modal" class="btn btn-danger">Kliknij aby potwierdzić.</a>

							</p>
						</div>							
					<?php 
} else {
    ?>
						<?php 
    echo anchor("/image/zoom/{$preview_image->id}" . '/' . url_slug($preview_image->title, array('transliterate' => TRUE)), img(array('src' => $thumb_preview_config['path'] . $preview_image->file_name, 'alt' => $preview_image->title)));
    ?>
					<?php 
}
?>
				</div>
			</div>
		</div>
	</li>	
</ul>
<?php 
if ($preview_image->plus_18 && !$adult_user && !(isset($logged_in_user) && $logged_in_user->id === $preview_image->user_id)) {
    ?>
	<div id="stop18-confirm-modal" class="modal hide fade">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal">×</button>
     while ($row = $cursor->fetch_assoc()) {
         if (url_slug($row['TITULO__CON']) == $what) {
             $cont = new Contenido($row['ID______CON']);
             $html = $cont->getHTML();
             $found = true;
             break;
         }
     }
 }
 if (!$found) {
     $proyectos = array();
     $c = 0;
     $f = 0;
     if ($cursor = $sql->readDB("CATEGORIA")) {
         while ($row = $cursor->fetch_assoc()) {
             if (url_slug($row['NOMBRE__CAT']) == $what) {
                 if ($subCursor = $sql->readDB("CATEGORIA", "PADRE___CAT=" . $row['ID______CAT'])) {
                     while ($rr = $subCursor->fetch_assoc()) {
                         $cat = $rr['ID______CAT'];
                         if ($subCursor2 = $sql->readDB("CONTENIDO", "ESTADO__CON='A' AND CATEGORICON='{$cat}'", "ORDEN___CON")) {
                             while ($rrr = $subCursor2->fetch_assoc()) {
                                 $cont = new Contenido($rrr['ID______CON']);
                                 $proyectos[$f][$rrr['ID______CON']] = $cont->getHTML(true);
                                 $c++;
                                 if ($c >= 4) {
                                     $c = 0;
                                     $f++;
                                 }
                             }
                         }
                     }
Example #29
0
 public function update()
 {
     $this->output->set_header('Content-Type: application/json; charset=utf-8');
     $this->load->helper('slug');
     $user = $this->ion_auth->user()->row();
     $this->load->library('form_validation');
     if ($this->input->post('song_id')) {
         $song_row = $this->Song_model->get_song($this->input->post('song_id'));
         $real_user_id = $song_row->user_id;
         $real_file_uid = $song_row->file_uid;
     } else {
         redirect('manage/songs', 'refresh');
     }
     if ($this->input->post('user_id') != $user->id && !$this->ion_auth->is_admin() && $this->input->post('song') != $real_file_uid) {
         redirect('manage/songs', 'refresh');
     } else {
         //modal form validaiton
         $this->form_validation->set_rules('artist', 'Artist', 'trim|required|min_length[2]|max_length[100]|xss_clean');
         $this->form_validation->set_rules('title', 'Title', 'trim|required|min_length[2]|max_length[100]|xss_clean');
         $this->form_validation->set_rules('featuring', 'Featuring', 'trim||min_length[2]|max_length[255]|xss_clean');
         $this->form_validation->set_rules('producer', 'Producer', 'trim|min_length[2]|max_length[255]|xss_clean');
         $this->form_validation->set_rules('album', 'Album', 'trim|min_length[2]|max_length[255]|xss_clean');
         $this->form_validation->set_rules('video', 'Video', 'trim|min_length[2]|xss_clean');
         $this->form_validation->set_rules('image', 'Image', 'trim|min_length[2]|xss_clean');
         $this->form_validation->set_rules('description', 'Description', 'trim|min_length[2]|max_length[10000]|xss_clean');
         $this->form_validation->set_rules('song_url', 'Song URL', 'trim|min_length[2]|max_length[255]|xss_clean');
         //hidden inputs
         $file_uid = $this->input->post('song');
         $song_id = $this->input->post('song_id');
         $file_name = $this->input->post('file_name');
         $user_id = $this->input->post('user_id');
         $artist = $this->input->post('artist', TRUE);
         $title = $this->input->post('title', TRUE);
         $featuring = $this->input->post('featuring', TRUE);
         $producer = $this->input->post('producer', TRUE);
         $album = $this->input->post('album', TRUE);
         $video = $this->input->post('video', TRUE);
         $buy_link = $this->input->post('buy_link', TRUE);
         $can_download = $this->input->post('can_download', TRUE);
         $description = $this->input->post('description', TRUE);
         $soundcloud_url = $this->input->post('soundcloud_url', TRUE);
         $published = 'published';
         $song = $this->Song_model->get_song($song_id);
         $username = $song->username;
         $urlslug = $song->song_url;
         $sfname = $song->sfname;
         $visibility = $this->input->post('make_private', TRUE) == 'yes' ? 'unlisted' : 'public';
         // if the user changed the soundcloud URL
         if ($soundcloud_url != $song->external_url) {
             $this->load->helper('soundcloud');
             $sc = json_decode(_resolveSoundcloud($soundcloud_url));
             if (!empty($sc->id)) {
                 $external_file = $sc->id;
             } else {
                 $external_file = $song->external_file;
             }
             $external_url = $soundcloud_url;
         } else {
             $external_file = $song->external_file;
             $external_url = $song->external_url;
         }
         if ($this->input->post('song_url') !== $song->song_url) {
             $urlslug = url_slug($this->input->post('song_url', TRUE));
         }
         //make sure its a youtube video
         if (preg_match('/^(?:https?:\\/\\/)?(?:www\\.)?youtube\\.com\\/watch\\?(?=.*v=((\\w|-){11}))(?:\\S+)?$/', $video)) {
             parse_str(parse_url($video, PHP_URL_QUERY), $my_array_of_vars);
             $video = $my_array_of_vars['v'];
         } else {
             $video = $video;
         }
         if ($this->form_validation->run() == FALSE) {
             //validation errors
             $output_array = array('validation' => 'error', 'message' => validation_errors('<div class="alert alert-error"><strong>Error!</strong> ', '</div>'));
             $this->output->set_output(json_encode($output_array));
         } else {
             if (!$this->Song_model->valid_song_exists(array('file_uid' => $file_uid, 'user_id' => $user_id, 'song_id' => $song_id))) {
                 //couldn't find song that matches the file_uid/user_id/file_name
                 $output_array = array('validation' => 'valid', 'response' => 'error', 'message' => 'It appears the song doesnt exist.');
                 $this->output->set_output(json_encode($output_array));
             } else {
                 if (isset($_FILES['image_file'])) {
                     $uploads = $_FILES['image_file'];
                     if ($uploads['error'] == 0) {
                         $this->load->library('images');
                         $this->images->uploadLocalFile($uploads, $sfname, $urlslug, $user_id);
                         $ext = pathinfo($uploads['name']);
                         $ext = $ext['extension'];
                         $image_dir = FCPATH . 'asset_uploads/' . $song->username . '/' . $urlslug . '/';
                         $size_array = array('64', '150', '300', '500');
                         foreach ($size_array as $size) {
                             $resize = $this->images->resizeImage($image_dir, $sfname, $ext, $size);
                         }
                         if (!$resize) {
                             $output_array = array('validation' => 'valid', 'response' => 'error', 'message' => 'Unable to resize image');
                             $this->output->set_output(json_encode($output_array));
                         }
                         $song_image = $sfname . '.' . $ext;
                     }
                 } else {
                     $song_image = $song->song_image;
                 }
                 $song_data = array('song_artist' => $artist, 'song_title' => $title, 'song_description' => $description, 'featuring' => $featuring, 'song_url' => $urlslug, 'song_producer' => $producer, 'album' => $album, 'file_name' => $file_name, 'video' => $video, 'song_image' => $song_image, 'external_file' => $external_file, 'external_url' => $external_url, 'buy_link' => $buy_link, 'status' => $published, 'visibility' => $visibility, 'can_download' => $can_download);
                 $update_where = array('file_uid' => $file_uid, 'user_id' => $user_id, 'song_id' => $song_id);
                 $song_row_updated = $this->Song_model->update($update_where, $song_data);
                 if (!$song_row_updated) {
                     $output_array = array('validation' => 'valid', 'response' => 'error', 'message' => 'The song was not updated. Did you make any changes?');
                     $this->output->set_output(json_encode($output_array));
                 } else {
                     //paydirt
                     if ($external_file != $song->external_file) {
                         //upload SC Image
                         $this->load->library('images');
                         $this->images->uploadRemoteFile($sc->artwork_url, $sfname, $urlslug);
                         $song_image = $sfname . '.jpg';
                         $image_dir = FCPATH . 'asset_uploads/' . $username . '/' . $urlslug . '/';
                         $size_array = array('64', '150', '300');
                         foreach ($size_array as $size) {
                             $this->images->resizeImage($image_dir, $sfname, 'jpg', $size);
                         }
                     }
                     //used to add more output to the returned json
                     $urlUpdated = NULL;
                     if ($this->input->post('song_url') !== $song->song_url) {
                         $urldata = array('old_url' => $song->song_url, 'current_url' => $urlslug, 'song_id' => $song->song_id, 'date_created' => time());
                         $updateUrl = $this->Song_model->addUpdatedUrl($urldata);
                         if ($updateUrl) {
                             $urlUpdated = "<br /><span style='font-weight:bold;font-size:1em'>The Song URL was updated as well. Please update your links accordingly.</span>";
                         }
                     }
                     //delete existing post cache
                     $sqlWhere = array('username' => $song->username, 'song_url' => $song->song_url);
                     $this->cache->model('Song_model', 'get_song_where', array($sqlWhere), -1);
                     $output_array = array('validation' => 'valid', 'response' => 'success', 'message' => 'Song updated. <a href="' . base_url('song/' . $username . '/' . $urlslug) . '">Click here to view</a>' . $urlUpdated);
                     $this->output->set_output(json_encode($output_array));
                 }
             }
         }
     }
     //end form_validation and JSON returns
 }
Example #30
0
 /**
  * modal on song player page sends data via AJAX to this function. 
  * Function is used to add a song to an existing playlist. 
  * Also used to create a new playlist.
  * @param  [string] $username - URI segment 2 from song player page, used to get the right song from the DB
  * @param  [string] $song_url - URI Segment 3 from song player page, used to get the right song from the DB
  * @return [json]
  */
 public function ajax_add_to_playlist($username = NULL, $song_url = NULL)
 {
     $this->output->set_header('Content-Type: application/json; charset=utf-8');
     //TODO --- MAKE THE NOT LOGGED IN THING WORK
     if (!$this->ion_auth->logged_in()) {
         $this->output->set_output(json_encode(array('response_type' => 'error', 'message' => 'Please Login', 'response_reason' => 'guest')));
     }
     $song = $this->Song_model->get_song_where(array('users.username' => $username, 'songs.song_url' => $song_url));
     $output_message = NULL;
     $output_URL = NULL;
     //used for deleting cache, need to get the correct
     $cache_playlist_ids = array();
     //create a playlist
     if ($this->input->post('playlist_name')) {
         $create = array('user_id' => $this->ion_auth->user()->row()->id, 'title' => $this->input->post('playlist_name'), 'status' => $this->input->post('status'), 'url' => url_slug($this->input->post('playlist_name')));
         //check if there is an existing playlist with the same URL
         $existing = $this->Playlist_model->get(array('playlists.url' => url_slug($this->input->post('playlist_name')), 'users.username' => $this->ion_auth->user()->row()->username), 1);
         if ($existing) {
             $existing = $existing[0];
             $output_message = 'EXISTING';
             $output_URL = 'playlist/' . $this->ion_auth->user()->row()->username . '/' . url_slug($this->input->post('playlist_name'));
             $cache_playlist_ids[] = $existing->id;
             $add_data = array('song_id' => $song->song_id, 'playlist_id' => $existing->id, 'position' => $existing->track_count + 1);
             $this->Playlist_model->add_track($add_data);
             $this->Playlist_model->update_track_count(array('id' => $existing->id), array('track_count' => 'track_count + 1'));
             $output = array('response' => 'success', 'message' => 'Added song to existing playlist', 'url' => $output_URL);
         } else {
             $create_list = $this->Playlist_model->add($create);
             if ($create_list) {
                 //successfully created the playlist, now add the song to the list
                 $add_data = array('song_id' => $song->song_id, 'playlist_id' => $create_list, 'position' => '1');
                 $cache_playlist_ids[] = $create_list;
                 $this->Playlist_model->add_track($add_data);
                 $this->Playlist_model->update_track_count(array('id' => $create_list), array('track_count' => 'track_count + 1'));
                 $output_URL = 'playlist/' . $this->ion_auth->user()->row()->username . '/' . url_slug($this->input->post('playlist_name'));
                 $output = array('response' => 'success', 'message' => 'Successfully created the playlist', 'url' => $output_URL);
             } else {
                 $output = array('response' => 'error', 'message' => 'Could not create the playlist');
             }
             //create_list
         }
         //existing
     }
     //add to existing
     if ($this->input->post('playlist_id')) {
         $playlist = $this->Playlist_model->get(array('playlists.id' => $this->input->post('playlist_id')));
         $playlist = $playlist[0];
         $playlist_ids = explode(',', $this->input->post('playlist_id'));
         foreach ($playlist_ids as $key => $pid) {
             $cache_playlist_ids[] = $pid;
             $add_data = array('song_id' => $song->song_id, 'playlist_id' => $pid, 'position' => $playlist->track_count + 1);
             $add = $this->Playlist_model->add_track($add_data);
             $this->Playlist_model->update_track_count(array('playlists.id' => $pid), array('playlists.track_count' => 'playlists.track_count + 1'));
             if ($add) {
                 if (!empty($output_message)) {
                     $output = array('response' => 'success', 'message' => 'Added the song to your existing Playlist');
                 } else {
                     $output = array('response' => 'success', 'message' => 'Successfully added song to playlist', 'url' => $output_URL);
                 }
             } else {
                 $output = array('response' => 'erorr', 'message' => 'Could not add the track');
             }
         }
     }
     $this->cache->model('Playlist_model', 'get', array(array('playlists.user_id' => $this->ion_auth->user()->row()->id)), -1);
     foreach ($cache_playlist_ids as $key => $cpi) {
         $this->cache->model('Playlist_model', 'get_tracks', array(array('playlist_id' => $cpi), 'position ASC'), -1);
     }
     $this->output->set_output(json_encode($output));
 }